XGPush集成(信鸽集成)

时间:2022-11-09 19:44:57
  #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具体解释&lpar;6&rpar;:集成信鸽推送

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

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

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

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

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

  4. android app 集成 信鸽推送

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

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

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

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

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

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

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

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

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

  9. CKEditor 集成CKFinder集成

    lCKEditor原名FckEditor,著名的HTML编辑器,可以在线编辑HTML内容,演示一下.打开.自己人用CKEditor,网友用UBBEditor. l配置参考文档,主要将ckeditor中 ...

随机推荐

  1. iPhone添加邮箱

    阿里云邮箱设置 手机自带的电子邮件客户端该如何添加阿里云邮账号呢?这里以iPhone4s和安卓系统为例,分别进行添加阿里云邮箱帐号的添加.   官网是这么介绍的:   一.如下以iPhone4s为例, ...

  2. Java 初学记录之可执行jar包

    环境 jdk7 jre7 当我用jdk7开发的时候,编写完成可执行的jar工具,并且成功使用. 当我在另一台机器安装了jre6,再次运行我的小工具jar 的时候,报错 解决: http://stack ...

  3. iOS开发之蓝牙通讯

    iOS开发之蓝牙通讯 一.引言 蓝牙是设备近距离通信的一种方便手段,在iPhone引入蓝牙4.0后,设备之间的通讯变得更加简单.相关的蓝牙操作由专门的CoreBluetooth.framework进行 ...

  4. 64位Windows2003下如何正确发布VesnData&period;Net&lpar;VDN&rpar;

    64位windows2003下发布VDN,按照正常的步骤会出现:试图加载格式不正确的程序. (异常来自 HRESULT:0x8007000B)的错误. 按照下面的步骤进行处理: 1.如果安装了64位F ...

  5. 表数据转换为insert语句

    /* 对象:导出物理表数据为Insert语句 描述:可以传递条件精确导出sql 加条件的前提是只知道相应的字段名及类型 */ from sysobjects where name ='proc_ins ...

  6. boost&period;asio系列——buffer

    创建buffer 在io操作中,对数据的读写大都是在一个缓冲区上进行的,在asio框架中,可以通过asio::buffer函数创建一个缓冲区来提供数据的读写.buffer函数本身并不申请内存,只是提供 ...

  7. &lbrack;Usaco2007 Dec&rsqb;宝石手镯&lbrack;01背包&rsqb;&lbrack;水&rsqb;

    Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为 ...

  8. Spring源码情操陶冶-AbstractApplicationContext&num;postProcessBeanFactory

    阅读源码有利于陶冶情操,承接前文Spring源码情操陶冶-AbstractApplicationContext#prepareBeanFactory 约定:web.xml中配置的contextClas ...

  9. birt 报表设计总结

    1, 通过sql查询出来的数据,当某个字段没有值时,我们期望显示别的东东 在表格单元格或者网格中选中这个值, 在属性编辑器-->映射--> 在映射表中添加映射条件 映射中当使用 等于 时, ...

  10. Js比较对Object类型进行排序

    <script> var data=[{name:"121",age:"18",year:"2018"},{name:&quot ...