AppDelegate+HandleOpen.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. //注:此方法在swift4.1(Xcode 9.3)已废弃,Objective-C项目不影响。 新浪 平台外的其他平台可在swift项目中使用下面两种回调方法。
  12. func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  13. //6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
  14. var result = UMSocialManager.default().handleOpen(url, sourceApplication: sourceApplication, annotation: annotation)
  15. if (!result) {
  16. // 其他如支付等SDK的回调
  17. result = PayManager.shared().handleOpen(url: url)
  18. return result
  19. }
  20. return result;
  21. }
  22. //仅支持iOS9以上系统,iOS8及以下系统不会回调
  23. func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
  24. //6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
  25. var result = UMSocialManager.default().handleOpen(url, options: options)
  26. if (!result) {
  27. // 其他如支付等SDK的回调
  28. result = PayManager.shared().handleOpen(url: url)
  29. return result
  30. }
  31. return result;
  32. }
  33. //支持目前所有iOS系统
  34. func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
  35. var result = UMSocialManager.default().handleOpen(url)
  36. if (!result) {
  37. // 其他如支付等SDK的回调
  38. result = PayManager.shared().handleOpen(url: url)
  39. return result
  40. }
  41. return result;
  42. }
  43. //iOS10以下使用这两个方法接收通知,
  44. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  45. //关闭友盟自带的弹出框
  46. UMessage.setAutoAlert(true)
  47. if #available(iOS 9.0, *) {
  48. if #available(iOS 10.0, *){
  49. }else {
  50. UMessage.didReceiveRemoteNotification(userInfo)
  51. completionHandler(UIBackgroundFetchResult.newData);
  52. }
  53. }
  54. }
  55. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
  56. //关闭友盟自带的弹出框
  57. UMessage.setAutoAlert(true)
  58. if #available(iOS 9.0, *) {
  59. if #available(iOS 10.0, *){
  60. }else {
  61. UMessage.didReceiveRemoteNotification(userInfo)
  62. }
  63. }
  64. }
  65. /// 获取设备的 DeviceToken
  66. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  67. NXLLog(deviceToken.description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: ""))
  68. }
  69. }