#import "AppDelegate.h"
#import "XGPush.h"
#import "XGSetting.h" #define _IPHONE80_ 80000 @implementation AppDelegate
- (void)registerPushForIOS8{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ //Types
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; //Actions
UIMutableUserNotificationAction *acceptAction = [[UIMutableUserNotificationAction alloc] init]; acceptAction.identifier = @"ACCEPT_IDENTIFIER";
acceptAction.title = @"Accept"; acceptAction.activationMode = UIUserNotificationActivationModeForeground;
acceptAction.destructive = NO;
acceptAction.authenticationRequired = NO; //Categories
UIMutableUserNotificationCategory *inviteCategory = [[UIMutableUserNotificationCategory alloc] init]; inviteCategory.identifier = @"INVITE_CATEGORY"; [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault]; [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextMinimal]; NSSet *categories = [NSSet setWithObjects:inviteCategory, nil]; UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories]; [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; [[UIApplication sharedApplication] registerForRemoteNotifications];
#endif
} - (void)registerPush{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //注册推送
[XGPush startApp: appKey:@"IXJ8177VC3BG"]; //注销之后需要再次注册前的准备
void (^successCallback)(void) = ^(void){
//如果变成需要注册状态
if(![XGPush isUnRegisterStatus])
{
//iOS8注册push方法
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
if(sysVer < ){
[self registerPush];
}
else{
[self registerPushForIOS8];
}
NSLog(@"sysVer ----------- %g", sysVer);
#else
//iOS8之前注册push方法
//注册Push服务,注册后才能收到推送
[self registerPush];
#endif
}
};
[XGPush initForReregister:successCallback]; //推送反馈回调版本示例
void (^successBlock)(void) = ^(void){
//成功之后的处理
NSLog(@"[XGPush]handleLaunching's successBlock");
}; void (^errorBlock)(void) = ^(void){
//失败之后的处理
NSLog(@"[XGPush]handleLaunching's errorBlock");
};
[XGPush handleLaunching:launchOptions successCallback:successBlock errorCallback:errorBlock];
//角标清0
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:]; //清除所有通知(包含本地通知)
[XGPush clearLocalNotifications];
//本地推送示例
// [XGPush handleLaunching:launchOptions successCallback:successBlock errorCallback:errorBlock];
//
// NSDate *fireDate = [[NSDate new] dateByAddingTimeInterval:5];
//
// NSMutableDictionary *dicUserInfo = [[NSMutableDictionary alloc] init];
// [dicUserInfo setValue:@"myid" forKey:@"clockID"];
// NSDictionary *userInfo = dicUserInfo;
//
// [XGPush localNotification:fireDate alertBody:@"测试本地推送" badge:2 alertAction:@"确定" userInfo:userInfo];
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark - Notification #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ //注册UserNotification成功的回调
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//用户已经允许接收以下类型的推送
//UIUserNotificationType allowedTypes = [notificationSettings types];
NSLog(@"didRegisterUserNotificationSettings");
} //按钮点击事件回调
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler{
if([identifier isEqualToString:@"ACCEPT_IDENTIFIER"]){
NSLog(@"ACCEPT_IDENTIFIER is clicked");
} completionHandler();
} #endif - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"Token----------------: %@", [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding]); NSString * deviceTokenStr = [XGPush registerDevice:deviceToken]; //注册设备
[XGPush setAccount:@""];
// [XGPush registerDevice:deviceToken]; void (^successBlock)(void) = ^(void){
//成功之后的处理
NSLog(@"[XGPush]register successBlock ,deviceToken: %@",deviceTokenStr);
}; void (^errorBlock)(void) = ^(void){
//失败之后的处理
NSLog(@"[XGPush]register errorBlock");
}; [XGPush registerDevice:deviceToken successCallback:successBlock errorCallback:errorBlock]; //打印获取的deviceToken的字符串
NSLog(@"deviceTokenStr is %@",deviceTokenStr);
} //如果deviceToken获取不到会进入此事件
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { NSString *str = [NSString stringWithFormat: @"Error: %@",err]; NSLog(@"%@",str); } - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{// 取得 APNs 标准信息内容
NSDictionary *aps = [userInfo valueForKey:@"aps"];
NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量
// badge += [UIApplication sharedApplication].applicationIconBadgeNumber; NSLog(@"didReceiveRemoteNotification badge = %ld, systemBadgeNumber = %ld", (long)badge, (long)[UIApplication sharedApplication].applicationIconBadgeNumber);
// [APService setBadge:badge];
NSLog(@"data:%@ --- dic:%@", aps, userInfo); [[UIApplication sharedApplication] setApplicationIconBadgeNumber:];
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];
NSString *sound = [aps valueForKey:@"sound"]; //播放的声音 // 取得自定义字段内容
NSString *customizeField1 = [userInfo valueForKey:@"customizeField1"]; //自定义参数,key是自己定义的
NSLog(@"content =[%@], badge=[%ld], sound=[%@], customize field =[%@]",content,(long)badge,sound,customizeField1);
//推送反馈(app运行时)
[XGPush handleReceiveNotification:userInfo]; } -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
//notification是发送推送时传入的字典信息
[XGPush localNotificationAtFrontEnd:notification userInfoKey:@"clockID" userInfoValue:@"myid"]; //删除推送列表中的这一条
// [XGPush delLocalNotification:notification];
//[XGPush delLocalNotification:@"clockID" userInfoValue:@"myid"]; //清空推送列表
//[XGPush clearLocalNotifications];
} @end
复制代码

XGPush集成(信鸽集成)的更多相关文章

  1. QtAndroid具体解释(6):集成信鸽推送

    推送是我们开发移动应用经经常使用到的功能,Qt on Android 应用也会用到,之前也有朋友问过,这次我们来看看怎么在 Qt on Android 应用中来集成来自腾讯的信鸽推送. 有关信鸽的 S ...

  2. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps 集成SP和Office App

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps  集成SP和Office App         你能够用两种 ...

  3. SpringBoot集成文件 - 集成POI之Excel导入导出

    Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程序对Microsoft Office格式档案读和写的功能.本文主要介绍通过Spr ...

  4. XGPush集成(信鸽集成)demo

    #import "AppDelegate.h" #import "XGPush.h" #import "XGSetting.h" #defi ...

  5. android app 集成 信鸽推送

    推送其实挺中意小米推送的,并经用户群占比还是比较大的,奈何拗不过php后端哥们的选型,就只好用信鸽推送了,期间接入过程中也是遇到不少问题,所以记录下来,以后如果还是用信鸽推送的话,估计看看以前的博客, ...

  6. 第三十三章 metrics(1) - graphite搭建 + whisper存储模式 + 高精度向低精度聚合方式 + 集成StatsD + 集成grafana

    组件介绍: carbon:Carbon实际上是一系列守护进程,组成一个Graphite安装的存储后端.这些守护进程用一个名为Twisted的事件驱动网络引擎监听时间序列数据.Twisted框架让Car ...

  7. Android开发支付集成——微信集成

    支付宝支付传送门:https://www.cnblogs.com/dingxiansen/p/9208949.html 二.微信支付 1. 微信支付流程图 相比较而言,微信支付是要比支付宝麻烦一些,并 ...

  8. Android开发支付集成——支付宝集成

    微信支付传送门:https://www.cnblogs.com/dingxiansen/p/9209159.html 一.支付宝支付 1. 支付宝支付流程图 2. 集成前准备 去蚂蚁金服注册应用获取a ...

  9. RocketMQ搭建-WEB集成RMQ-SE集成RMQ

    坑一 https://blog.csdn.net/c_yang13/article/details/76836753 JAVAWEB集成RMQ https://www.cnblogs.com/yun9 ...

随机推荐

  1. 基于GPL329xx linux平台电容屏gsl1680的驱动调试分析

    因客户有用到了gsl1680 7寸电容屏,所以拿了一块过来,便在329xx的平台上面开始调试了. 大概浏览了一下所提供的资料,只有介绍模组的资料跟一份中文版的datasheet,datasheet只是 ...

  2. bzoj 1097 [POI2007]旅游景点atr(最短路,状压DP)

    [题意] 给定一个n点m边的无向图,要求1开始n结束而且顺序经过k个点,给出经过关系x,y代表y必须在x之后经过,求最短路. [思路] 先对k个点进行spfa求出最短路. 设f[s][i]代表经过点集 ...

  3. 叉积判断 POJ1696

    // 叉积判断 POJ1696 #include <iostream> #include <algorithm> #include <cstring> #inclu ...

  4. OpenCV中IplImage和Mat间的相互转换

    OpenCV中做图像处理经常用到IplImage和Mat间的相互转换. 首先,cv::Mat是opencv2.0中的数据类型:IplImage是opencv1.0中的类型,两种类型并不相同. 1. I ...

  5. Eclipse与tomcat服务器建立关联

    首先,点击 打开preference,打开如下界面 点击ADD,进入如下界面,选择tomcat服务器的版本->点击next 进入如下界面,Name:服务器名字,directory:服务器目录 补 ...

  6. int.class与Integer.type的不同

    int.class返回Integer的对象 Integer.type返回int对象

  7. 第二百五十八天 how can I 坚持

    装虚拟机了.CentOs,32位,这电脑装4台能不能带起来啊. 早上,流鼻血了,不知道咋回事.太干了... 明天得早起会,得利索着点,不能托托拉拉的. 还有,今天又忘带钥匙了.悲剧. 睡觉.hadoo ...

  8. 现代程序设计 homework-05

    本次作业要求设计服务器和客户端,由于之前对网络编程是一窍不通,上上节课听宗学长讲述Tcp的时候心里想这个东西还真是高大上啊一点儿都听不懂,但是上个周末看了看C#网络编程的博客和书之后,发现这个东西入门 ...

  9. iOS本地数据存取

    应用沙盒 1)每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 2)应用沙盒的文件系统目录,如下图所示(假设应用的名称 ...

  10. eclipse中如何设置tomcat启动时间

    现象:在eclipse中启动tomcat总是提示“Server Tomcat v5.5 Server @ localhost was unable to start within 45 seconds ...