#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. 多校7 HDU5818 Joint Stacks

    多校7 HDU5818 Joint Stacks 题意:n次操作.模拟栈的操作,合并的以后,每个栈里的元素以入栈顺序排列 思路:开三个栈,并且用到了merge函数 O(n)的复杂度 #include ...

  2. [Hive - LanguageManual] Hive Default Authorization - Legacy Mode

    Disclaimer Prerequisites Users, Groups, and Roles Names of Users and Roles Creating/Dropping/Using R ...

  3. 为Elasticsearch添加中文分词

    Elasticsearch的中文分词很烂,所以我们需要安装ik.首先从github上下载项目,解压: cd /tmp wget https://github.com/medcl/elasticsear ...

  4. android sdk manager 闪退 打不开问题

    android sdk manager 闪退 打不开问题 环境 win8系统 如果访问不了  dl-ssl.google.com 网址,在C:\Windows\System32\Drivers\etc ...

  5. vim MiniBufExplorer 插件

    MiniBufExplorer安装好久了,但一直没怎么使用过. 今天查了下资料,作为一个备份. 当你只编辑一个buffer的时候MiniBufExplorer派不上用场, 当 你打开第二个buffer ...

  6. HDU 5783 Divide the Sequence (贪心)

    Divide the Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...

  7. Http Header Content-Disposition

    Content-Disposition用途 Content-Disposition是为了实现服务器下载文件功能,并可提供文件名. Content-Disposition格式 content-dispo ...

  8. 在MVC项目中使用RDLC报表

    原文地址:http://www.cnblogs.com/wuhuacong/p/4109833.html RDLC是一个不错的报表,有着比较不错的设计模式和展现效果,在我的Winform开发里面,使用 ...

  9. get_template_part() 函数详解备忘(转)

    最近研究官方主题 Twenty Eleven ,有一些东西网上现成的中文资料不好找,在博客里记载下来,算是分享,也算是备忘,wordpress 3.0 以后就开始便有了get_template_par ...

  10. 令人惊奇的gdb和pstack

    pstack竟然是一个shell脚本,核心是调用gdb的thread apply all bt查看进程的所有线程的堆栈,之后用sed正则展示线程堆栈信息. /proc/pid/exe是一个指向可执行文 ...