极光推送
2016-05-17 21:42
169 查看
//APP启动,通知处理
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
//清除所有的通知
[APService
clearAllLocalNotifications];
//JPush
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
if ([[UIDevice
currentDevice].systemVersion
floatValue] >= 8.0) {
//可以添加自定义categories
[APService
registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories
必须为nil
[APService
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
#else
//categories 必须为nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
#endif
// Required
[APService
setupWithOption:launchOptions];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated
later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
[[UIApplication
sharedApplication] setApplicationIconBadgeNumber:0];
[APService
resetBadge];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
[application setApplicationIconBadgeNumber:0];
[APService
resetBadge];
}
//JPush
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData
*)deviceToken {
// Required
[APService
registerDeviceToken:deviceToken];
NSLog(@"deviceToken : %@",deviceToken);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError
*)error {
NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo {
// Required
[APService
handleRemoteNotification:userInfo];
NSLog(@"收到通知",
);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
//NSLog(@"application.applicationState =%d",application.applicationState);
if (userInfo) {
[APService
handleRemoteNotification:userInfo];
}
completionHandler(UIBackgroundFetchResultNewData);
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
//清除所有的通知
[APService
clearAllLocalNotifications];
//JPush
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
if ([[UIDevice
currentDevice].systemVersion
floatValue] >= 8.0) {
//可以添加自定义categories
[APService
registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories
必须为nil
[APService
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
#else
//categories 必须为nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
#endif
// Required
[APService
setupWithOption:launchOptions];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated
later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
[[UIApplication
sharedApplication] setApplicationIconBadgeNumber:0];
[APService
resetBadge];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
[application setApplicationIconBadgeNumber:0];
[APService
resetBadge];
}
//JPush
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData
*)deviceToken {
// Required
[APService
registerDeviceToken:deviceToken];
NSLog(@"deviceToken : %@",deviceToken);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError
*)error {
NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo {
// Required
[APService
handleRemoteNotification:userInfo];
NSLog(@"收到通知",
);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
//NSLog(@"application.applicationState =%d",application.applicationState);
if (userInfo) {
[APService
handleRemoteNotification:userInfo];
}
completionHandler(UIBackgroundFetchResultNewData);
}
相关文章推荐
- POJ 1664 放苹果
- HDU 2136 Largest prime factor(素数筛选+打表)
- 50.字符流中第一个不重复的字符
- Java基本数据类型
- Linux的五个查找命令 [转]
- 向国外作者发邮件要代码
- c++中vector的用法详解
- 各种加解密算法比较
- ImageLoader
- 如何通过使用匿名内部类来将线程代码隐藏在类中
- POJ 2312 Battle City【Bfs+优先队列】
- [置顶] Linux下使用nexus搭建maven私服
- 作用域运算符的有什么功能
- LeetCode Reverse Words in a String
- Ubuntu下启动Eclipse报错:A Java RunTime Environment (JRE) or Java Development Kit (JDK) must
- MATLAB中的矩阵建立
- java之判断输入的字符类型个数
- 坦克大战(版本0.1-版本0.9)
- 内联函数
- C++实现委托机制(三)——lambda表达式封装