push notification获取device token

第一步:申请证书:

 

 

第二步:申请app ids,应用名字必须一致。然后再进入进行编辑,使其enable,绿灯。

 

 

第三步:申请provisioning profile,生成.mobileprovision,双击该证书才能正确导入手机设备,不能拖。

 

 

第四步:创建应用,使其名字一致。

 

第五步:写代码

 

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    // Override point for customization after application launch.

//    return YES;

    UIRemoteNotificationType types =

    (UIRemoteNotificationTypeBadge

     |UIRemoteNotificationTypeSound

     |UIRemoteNotificationTypeAlert);

    

    //注册消息推送

    [[UIApplication sharedApplication]registerForRemoteNotificationTypes:types];

    return YES;

    

}

 

//获取DeviceToken成功

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

    NSLog(@"DeviceToken: {%@}",deviceToken);

    //这里进行的操作,是将Device Token发送到服务端

    

    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil message:[NSStringstringWithFormat:@"DeviceToken:%@",deviceToken] delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",nil];

    [alert show];

}

 

//注册消息推送失败

- (void)application:(UIApplication *)application

didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

{

    NSLog(@"Register Remote Notifications error:{%@}",error);

    //    NSLog(@"Register Remote Notifications error:{%@}",error.localizedDescription);

}

 

//处理收到的消息推送

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo

{

    NSLog(@"Receive remote notification : %@",userInfo);

    UIAlertView *alert =

    [[UIAlertView alloc] initWithTitle:@"温馨提示"

                               message:@"推送成功!"

                              delegate:nil

                     cancelButtonTitle:@"确定"

                     otherButtonTitles:nil];

    [alert show];

}

 

转载于:https://www.cnblogs.com/soulDn/p/6019012.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值