#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集成(信鸽集成)demo的更多相关文章

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

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

  2. .Net集成PayPal的Demo

    .Net集成PayPal的Demo 近来项目中需要使用Paypal(贝宝)支付,研究了一下接口,真是吐血,花了一个下午+一个晚上,屡败屡战,海淘了若干文档,终于尝试成功了,分享一下,希望对将要使用pa ...

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

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

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

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

  5. XGPush集成(信鸽集成)

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

  6. android app 集成 信鸽推送

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

  7. ios native工程集成react-native的demo

    react-native看到了给现有工程添加react-native环境的时候碰到一个问题: 如何往工程中添加 package.json文件,以及node_modules是怎么来的? 我开始的时候以为 ...

  8. Android集成人脸识别demo分享

    本应用来源于虹软人工智能开放平台,人脸识别技术工程如何使用? 1.下载代码 git clone https://github.com/andyxm/ArcFaceDemo.git 2.下载虹软人脸识别 ...

  9. springboot 集成kaptcha验证码Demo

    验证码(CAPTCHA)是“Completely Automated Public Turing test to tell Computers and Humans Apart”(全自动区分计算机和人 ...

随机推荐

  1. M​i​c​r​o​s​o​f​t​ ​w​e​b​ ​a​p​p​l​i​c​a​t​i​o​n​ ​s​t​r​e​s​s​ ​t​o​o​l​ 测试

    一.准备工作 为了测试数据的准备性,首先需要删除缓存和Cookies等临时文件.启动IE后打开“工具”菜单下的“Internet”选项命令,在打开的“Internet选项”窗口的“常规”选项卡中,单击 ...

  2. Delphi中TWebBrowser中注入Js

    最近帮朋友做一个软件,其中要自动化某网页中的操作,最简的操作是调用自己写的代码. 代码如下: procedure TForm1.Button2Click(Sender: TObject);var  i ...

  3. vs错误【C1083 C1854 C4727】的若干解决办法(对预编译文件头的解释)

    这几天写程序,无意间把编译中间文件给删了,然后就出现了C1083编译错误. xxx.cpp ..\commen\xxx.cpp(2) : fatal error C1083: 无法打开预编译头文件:“ ...

  4. rsyslog masg和rawmsg的区别

    msg the MSG part of the message (aka "the message" ;)) message 的MSG 部分 rawmsg the message ...

  5. Trunk Club:颠覆男士时装零售的创业公司_第1页_福布斯中文网

    Trunk Club:颠覆男士时装零售的创业公司_第1页_福布斯中文网 Trunk Club:颠覆男士时装零售的创业公司

  6. Dot模板的使用小结2

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. How Many Equations Can You Find(dfs)

    How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  8. Leetcode:Swap Nodes in Pairs 单链表相邻两节点逆置

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

  9. 【leetcode系列】Valid Parentheses

    非常经典的问题,使用栈来解决,我这里自己实现了一个栈,当然也能够直接用java自带的Stack类. 自己实现的栈代码: import java.util.LinkedList; class Stack ...

  10. cocos2d-x -- 渠道SDK【棱镜】接入(2)

    上一章<cocos2d-x -- 渠道SDK[棱镜]接入(1)>,已经接入好了SDK.如今要准备加入渠道了,以豌豆荚为例. 详细流程: 1.加入渠道: