AppDelegate+HandleOpen.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // AppDelegate+HandleOpen.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/3/8.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import Foundation
  9. //MARK: - 设置系统回调
  10. extension AppDelegate {
  11. //仅支持iOS9以上系统,iOS8及以下系统不会回调
  12. func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
  13. //6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
  14. var result = UMSocialManager.default().handleOpen(url, options: options)
  15. if (!result) {
  16. // 其他如支付等SDK的回调
  17. result = PayManager.shared().handleOpen(url: url)
  18. if !result {
  19. // 自己路由
  20. result = RouterManager.shared.handleOpen(url: url)
  21. return result
  22. }
  23. return result
  24. }
  25. return result;
  26. }
  27. //支持目前所有iOS系统
  28. func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
  29. var result = UMSocialManager.default().handleOpen(url)
  30. if (!result) {
  31. // 其他如支付等SDK的回调
  32. result = PayManager.shared().handleOpen(url: url)
  33. if !result {
  34. // 自己路由
  35. result = RouterManager.shared.handleOpen(url: url)
  36. return result
  37. }
  38. return result
  39. }
  40. return result;
  41. }
  42. //iOS10以下使用这两个方法接收通知,
  43. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  44. //关闭友盟自带的弹出框
  45. UMessage.setAutoAlert(false)
  46. UMessage.didReceiveRemoteNotification(userInfo)
  47. RouterManager.shared.UMPush(pushModel: PushModel(JSONString: userInfo.description) ?? PushModel())
  48. completionHandler(UIBackgroundFetchResult.newData);
  49. }
  50. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
  51. //关闭友盟自带的弹出框
  52. UMessage.setAutoAlert(false)
  53. RouterManager.shared.UMPush(pushModel: PushModel(JSONString: userInfo.description) ?? PushModel())
  54. // 接受笑死通知
  55. UMessage.didReceiveRemoteNotification(userInfo)
  56. }
  57. /// 获取设备的 DeviceToken
  58. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  59. UMessage.registerDeviceToken(deviceToken)
  60. }
  61. }