[Object-C]使用个推遇到的坑
2015-07-31 17:26
896 查看
个推
一.简单介绍个推的功能
在iOS 个推是不能够发送"推送通知"的,只能使用"透传消息".描述: 就是关于这次透传信息的一个描述, 可以理解为表示, 没有什么实际的意义.
消息内容: 也就是最重要的我们需要的消息体.透传的消息内容.
Message: 这个我并没有收到过这样的信息.目前忽略不计, 但是需要填.
二. 关于代码集成.
// [1]:使用APPID/APPKEY/APPSECRENT创建个推实例 [self startSdkWith:kAppId appKey:kAppKey appSecret:kAppSecret]; // [2]:注册APNS [self registerRemoteNotification]; // [2-EXT]: 获取启动时收到的APN数据 NSDictionary* message = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (message) { NSString *payloadMsg = [message objectForKey:@"payload"]; NSString *record = [NSString stringWithFormat:@"[APN]%@, %@", [NSDate date], payloadMsg]; } NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
- (void)GeTuiSdkDidReceivePayload:(NSString *)payloadId andTaskId:(NSString *)taskId andMessageId:(NSString *)aMsgId fromApplication:(NSString *)appId { // [4]: 收到个推消息 _payloadId = payloadId; NSData* payload = [GeTuiSdk retrivePayloadById:payloadId]; NSString *payloadMsg = nil; if (payload) { payloadMsg = [[NSString alloc] initWithBytes:payload.bytes length:payload.length encoding:NSUTF8StringEncoding]; } NSData *jsonData = [payloadMsg dataUsingEncoding:NSUTF8StringEncoding]; NSError *err; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]; NSString *record = [NSString stringWithFormat:@"%d, %@, %@", ++_lastPaylodIndex, [self formateTime:[NSDate date]], payloadMsg]; NSLog(@"--+==+---%@", record); // [4]: 收到个推消息 // _payloadId = nil; // _payloadId = payloadId; // NSLog(@"%@----%@----%@---%@", payloadId,taskId, aMsgId, appId); // NSData* payload = [GeTuiSdk retrivePayloadById:payloadId]; // // NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:payload options:NSJSONReadingMutableContainers error:nil]; NSLog(@"%@",dic); UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //localNotification.userInfo = userinfo; localNotification.soundName = UILocalNotificationDefaultSoundName; if (dic) { localNotification.alertBody = [dic objectForKey:@"content"]; }else{ localNotification.alertBody = payloadMsg; } localNotification.fireDate = [NSDate date]; self.userInfo = [NSDictionary dictionaryWithDictionary:dic]; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; }
三. 关于 上传项目遇到的坑.
1. app被拒.原因:
Your app declares support for audio in the UIBackgroundModes key in your Info.plist, but we were unable to play any audiblecontent when the application was running in the background.
Next Steps
The audio key is intended for use by applications that provide audible content to the user while in the background, such as music player or streaming
audio applications. Please revise your app to provide audible content to the user while the app is in the background or remove the "audio" setting from the UIBackgroundModes key.
2. 怎么解决吗?
原来是这样的.但是为什么会出现这个呢? 原来发现个推会自动添加这个东西.....
3.把这个东西去掉之后, 好像是app在后台不能接收到推送了, 这个什么情况呢?
原来, 等到把这个去掉之后,app在后台的时候,个推就停止工作了.那怎么办? 好吧,去去掉一句话吧- (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. // [EXT] 切后台关闭SDK,让SDK第一时间断线,让个推先用APN推送 // [self stopSdk]; //[GeTuiSdk enterBackground]; // 这样个推在app在后台的时候也会工作. }
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- JavaScript代码编写中各种各样的坑和填坑方法
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- Python程序员鲜为人知但你应该知道的17个问题
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- MongoDB中的一些坑(最好不要用)
- IOS 改变键盘颜色代码
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- iOS开发之路--微博OAuth授权_取得用户授权的accessToken
- ios通过按钮点击异步加载图片