#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] 获取到通知对象
if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
NSLog(@"UIApplicationLaunchOptionsRemoteNotificationKey");
}
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategoryalloc]init];
category.identifier = @"QQ";
UIMutableUserNotificationAction *action = [[UIMutableUserNotificationActionalloc]init];
action.identifier = @"delete";
action.title = @"删除";
action.destructive = YES;
[category setActions:@[action]forContext:UIUserNotificationActionContextDefault];
//三行
UIUserNotificationSettings *setting = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeAlert |UIUserNotificationTypeSound | UIUserNotificationTypeBadgecategories:[NSSetsetWithObject:category]];
[[UIApplicationsharedApplication]registerUserNotificationSettings:setting];
//注册远程推送通知的时候就会生成一个deviceToken
[[UIApplicationsharedApplication]registerForRemoteNotifications];
//代理返回数据给你
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
//eafaceb5 e9029858 7ce649c7 54861ee2 24fc652a 6a0870dc d52aa41b 287c2264
NSLog(@"%@",deviceToken);
}
//接收到远程推送就会调用 程序活着的时候才会调用
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"didReceiveRemoteNotification");
}
//接收到远程推送就会调用 7.0
//- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
//{
// NSLog(@"didReceiveRemoteNotification");
// /*
// UIBackgroundFetchResultNewData,
// UIBackgroundFetchResultNoData,
// UIBackgroundFetchResultFailed
// */
// //反馈 处理的结果
// completionHandler(UIBackgroundFetchResultNewData);
//}