首页 > 其他分享 >IOS Push notification 摘要

IOS Push notification 摘要

时间:2022-10-10 21:39:35浏览次数:47  
标签:nil notification IOS application NSString error Push NSLog UIApplication


2.​​registerForRemoteNotificationTypes: is not supported ​​​​in​​​ ​​iOS 8.0 and later. 报错​

解决办法可参考:http://stackoverflow.com/questions/24454033/registerforremotenotificationtypes-is-not-supported-in-ios-8-0-and-later

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//This code will work in iOS 8.0 xcode 6.0 or later
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
return YES;
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSString* deviceToken1 = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""] ;
NSLog(@"Device_Token -----> %@\n",deviceToken1);

 

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"userinfo : %@",userInfo);
NSString *result = [self DataTOjsonString:userInfo];

UIAlertView * al = [[UIAlertView alloc]initWithTitle:result message:nil delegate:self cancelButtonTitle:@"✅" otherButtonTitles:nil];
[al show];
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"Failed to get token,error:%@",error);
}

-(NSString*)DataTOjsonString:(id)object
{
NSString *jsonString = nil;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}



 

3.APNS server(java):

2.Java APNS(notnoop) demo : http://ramosli.iteye.com/blog/1955465

 

标签:nil,notification,IOS,application,NSString,error,Push,NSLog,UIApplication
From: https://blog.51cto.com/u_15740686/5745308

相关文章

  • Linux磁盘相关工具 -- iostat
    iostat主要用于监控系统设备的IO负载情况,根据这个可以看出当前系统的写入量和读取量,CPU负载和磁盘负载。iostat主要用于输出磁盘IO和CPU统计信息。1. iostat用法:iostat......
  • axios完整配置请求数据
    <scripttype="module">importaxiosfrom'./lib/axios.min.js'//axios完整配置请求语法:axios(config)axios({url:'/admin/detail',//url会拼接在......
  • Flutter(六):Flutter_Boost接入现有原生工程(iOS+Android)
    一、新建原生工程和FlutterModule1、新建Android工程搭建一个空的Android工程FlutterDemo_Android模拟已经存在的原有工程Android项目配置:2、新建iOS工程搭建一个空......
  • MobPush Android For Unity
    集成准备注册账号使用MobSDK之前,需要先在MobTech官网注册开发者账号,并获取MobTech提供的AppKey和AppSecret,详情可以​​点击查看注册流程​​下载MobPush对应的.unitypackag......
  • iostat命令
    一、概述iostat主要用于输出磁盘IO和CPU的统计信息iostat属于sysstat软件包,可以用yum installsysstat直接安装二、iostat用法1、用法:iostat[选项][<时间间隔>......
  • Axios 取消重复请求
    在实际开发中,我们需要对用户发起的重复请求进行拦截处理,比如用户快速点击提交按钮解决办法1、新建request.jsimportaxiosfrom'axios'//创建axios实例constse......
  • git push 的本质
    进阶2:push的本质在之前的内容里,我粗略地说过,push 指令做的事是把你的本地提交上传到中央仓库去,用本地的内容来覆盖掉远端的内容。这个说法其实是不够准确的,但Git的知......
  • Vue3使用axios
    如何在Vue项目中使用axios请求http://www.45fan.com/article.php?aid=1D82KNnQB62JUc6OVue3-使用axios发起网络请求https://blog.csdn.net/liuyuxin36/article/details/......
  • axios取消上一个请求
      链接,里面有效果,亲测有效果https://codesandbox.io/s/simple-example-of-cancelling-axios-request-kyrnc?file=/src/App.vue:1074-1096这个可能需要外网才能打开,要......
  • 三、Axios入门——Axios的CRUD基本使用
    一、启动json-server服务详细教程:https://www.cnblogs.com/wml-it/p/16773220.html二、搭建页面<!doctypehtml><htmllang="en"><head><metacharset="UTF-8">......