Commit 92d9087e authored by David黄金龙's avatar David黄金龙

推送相关的bug

parent 9209ab13
......@@ -24,15 +24,21 @@ extension AppDelegate: JPUSHRegisterDelegate {
// init Push
// notice: 2.1.5 版本的 SDK 新增的注册方法,改成可上报 IDFA,如果没有使用 IDFA 直接传 nil
//初始化极光推送服务,调用了本 API 后,开启 JPush 推送服务,将会开始收集上报 SDK 业务功能所必要的用户个人信息
// [JPUSHService setupWithOption:launchOptions appKey:appKey
// channel:channel
// apsForProduction:isProduction
// advertisingIdentifier:advertisingId];
// [JPUSHService setupWithOption:launchOptions appKey:appKey
// channel:channel
// apsForProduction:isProduction
// advertisingIdentifier:advertisingId];
#if DEBUG
let isProduction = false
#elseif TESTENV
let isProduction = true
#else
let isProduction = true
#endif
JPUSHService.setup(withOption:launchOptions,
appKey:"c6a9e10575b85ee90f3e8afe",
channel:"",
channel:"appStore",
apsForProduction: isProduction)
}
......@@ -42,23 +48,39 @@ extension AppDelegate: JPUSHRegisterDelegate {
print("deviceToken:\(deviceTokenStr)")
JPUSHService.registerDeviceToken(deviceToken)
YHLoginManager.shared.deviceTokenModel.deviceToken = deviceTokenStr
#if DEBUG
YHHUD.flash(message: deviceTokenStr)
#elseif TESTENV
YHHUD.flash(message: deviceTokenStr)
#else
#endif
}
//获取token 失败
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { //可选
print("did Fail To Register For Remote Notifications With Error: \(error)")
#if DEBUG
YHHUD.flash(message: error.localizedDescription)
#elseif TESTENV
YHHUD.flash(message: error.localizedDescription)
#else
#endif
}
//点推送进来执行这个方法
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
JPUSHService.handleRemoteNotification(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
JPUSHService.handleRemoteNotification(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
// 转换到消息tab
YHLoginManager.shared.needJumpToMsgTabFlag = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: {
goTabBarBy(tabType: .message)
})
}
//后台进前台
......@@ -75,9 +97,9 @@ extension AppDelegate: JPUSHRegisterDelegate {
if notification.request.trigger is UNPushNotificationTrigger {
JPUSHService.handleRemoteNotification(userInfo)
}
// 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
completionHandler(Int(UNNotificationPresentationOptions.alert.rawValue))
// 显示通知时需要刷新消息列表和消息未读总数
// 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
completionHandler(Int(UNNotificationPresentationOptions.alert.rawValue))
// 显示通知时需要刷新消息列表和消息未读总数
DispatchQueue.main.async {
// 请求消息未读总数通知
NotificationCenter.default.post(name: YhConstant.YhNotification.didRequestUnreadMsgTotalCountNotification, object: nil)
......@@ -85,9 +107,9 @@ extension AppDelegate: JPUSHRegisterDelegate {
NotificationCenter.default.post(name: YhConstant.YhNotification.didRequestUnreadMsgListNotification, object: nil)
}
}
func jpushNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: (() -> Void)) {
let userInfo = response.notification.request.content.userInfo
let userInfo = response.notification.request.content.userInfo
if response.notification.request.trigger is UNPushNotificationTrigger {
JPUSHService.handleRemoteNotification(userInfo)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment