关闭

推送消息的时候判断是在app里面还是点击消息进去的 (配合Jpush极光)

194人阅读 评论(0) 收藏 举报
//接收远程推送通知内容(IOS6 以下)
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
}

</pre><p class="p1"><pre name="code" class="objc">//接收远程推送通知内容(IOS7 以上)
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
    // 取得 APNs 标准信息内容
    NSDictionary *aps = [userInfo valueForKey:@"aps"];
    NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
    NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量
    NSString *sound = [aps valueForKey:@"sound"]; //播放的声音
    
    // 取得自定义字段内容
    NSString *customizeField1 = [userInfo valueForKey:@"customizeField1"]; //自定义参数,key是自己定义的
    NSLog(@"在fetchCompletionHandler content =[%@], badge=[%ld], sound=[%@], customize field  =[%@]",content,(long)badge,sound,customizeField1);
    
    if (application.applicationState == UIApplicationStateActive) {
         NSLog(@"程序在运行状态UIApplicationStateActive");
    }
    else
    {
        NSLog(@"程序不再在在运行状态UIApplicationStateActive");
        //这个是点击推送消息进去的状态
        if ([aps valueForKey:@"category"]) {
            NSDictionary *dic = [NSDictionary dictionaryWithObject:[aps valueForKey:@"category"] forKey:@"dic"];
            [[NSNotificationCenter defaultCenter]postNotificationName:@"JpushPushWebview" object:nil userInfo:dic];
        }
        
        
    }


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14644次
    • 积分:893
    • 等级:
    • 排名:千里之外
    • 原创:77篇
    • 转载:5篇
    • 译文:0篇
    • 评论:0条
    文章分类