[Object-C]使用个推遇到的坑

个推

一.简单介绍个推的功能

     在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 audible content 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在后台的时候也会工作.
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值