极光推送iOS10前台收到推送 不使用弹窗提醒 加进通知栏方法

#pragma mark iOS 10 前台收到通知(远程推送本地通知)

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {

    NSDictionary * userInfo = notification.request.content.userInfo;

    if([notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {

        /// iOS10处理远程推送

        [JPUSHServicehandleRemoteNotification:userInfo];

        pushDic = userInfo;

        /// 应用处于前台收到推送的时候转成本地通知 ===========================

        UILocalNotification *notification = [[UILocalNotificationalloc] init];

        notification.alertTitle =@"哈哈哈哈哈";

        notification.alertBody =@"aaaaaa";

        notification.userInfo = userInfo;

        [[UIApplicationsharedApplication] presentLocalNotificationNow:notification];

    }else{

        /// 应用处于前台收到本地通知不会出现在通知中心 借用极光推送的方法将本地通知添加到通知栏 ==============================

        completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);

    }

    // 需要执行这个方法,选择是否提醒用户,有BadgeSoundAlert三种类型可以选择设置

}

/// 程序运行于前台,后台 或杀死 点击推送通知 都会走这个方法

 - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {

    // Required

    NSDictionary * userInfo = response.notification.request.content.userInfo;

    if([response.notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {

        [JPUSHServicehandleRemoteNotification:userInfo];

/// 杀死,后台点击通知栏 处理远程推送的跳转

        [selfreciveNotification:userInfo];

    }else{

         /// 前台运行时 转的本地通知 直接通知栏弹窗进行跳转处理

        [selfreciveNotification:userInfo];

    }

    completionHandler();  // 系统要求执行这个方法

}



  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值