iOS9一下远程推送代码实现

#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);

//}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值