iOS 推送 获取手机设备的 deviceToken
第一步:申请证书:
第二步:申请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:[NSString stringWithFormat:@"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];
}
相关文章
- Objc将数据写入iOS真机的plist文件中
- 怎样将游戏从Unity导到iOS设备上
- 判断不同IOS设备
- Unity3D开发之“获取IOS设备所在的国家代码"
- 获取IOS 设备基本信息
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)
- IOS开发--仿制网易新闻
- 获取iOS设备当前ip地址
- IOS谓词--NSPredicate
- IOS开发之----四舍五入问题
- iOS开发UI篇—IOS开发中Xcode的一些使用技巧
- iOS开发UI篇—常见的项目文件介绍
- iOS中 蓝牙2.0详解/ios蓝牙设备详解
- IOS UILabe及UIFont用法总结
- 在Windows笔记本上调试运行在iOS设备上的前端应用
- 在Windows笔记本上调试运行在iOS设备上的前端应用
- iOS swift 输入框(UITextField)密码明暗文切换
- iOS swift extensions
- ios蓝牙扫描指定的设备scanForPeripheralsWithServices(过滤掉其他设备,只留下自家设备)
- cordova(android ios) ota给蓝牙设备升级
- Appium - Android 对照 iOS
- iOS 执行ScrollView在空白空间-解
- 抖音成牛年春晚独家合作伙伴;微信8.0安卓/IOS版正式更新;孙正义辞去软银董事长…