美文网首页iOS
iOS10新增:处理前台收到通知的代理方法

iOS10新增:处理前台收到通知的代理方法

作者: 俊而不逊 | 来源:发表于2018-12-06 10:54 被阅读0次
    #pragma mark -- iOS10新增:处理前台收到通知的代理方法
    - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
        NSDictionary * userInfo = notification.request.content.userInfo;
        if (@available(iOS 10.0, *)) {
            if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
                //应用处于前台时的远程推送接受
                //关闭U-Push自带的弹出框
                [UMessage setAutoAlert:NO];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"userInfoNotification" object:self userInfo:userInfo];
                //必须加这句代码
                [UMessage didReceiveRemoteNotification:userInfo];
            } else {
                //应用处于前台时的本地推送接受
            }
        } else {
            // Fallback on earlier versions
        }
        //当应用处于前台时提示设置,需要哪个可以设置哪一个
        if (@available(iOS 10.0, *)) {
    completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
        } else {
            // Fallback on earlier versions
        }
    }
    

    相关文章

      网友评论

        本文标题:iOS10新增:处理前台收到通知的代理方法

        本文链接:https://www.haomeiwen.com/subject/jnmncqtx.html