Ver código fonte

友盟处理

nanxinlin 6 anos atrás
pai
commit
6692f22a02

+ 0 - 4
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -62,7 +62,6 @@
 		A72A730022321EE900B21995 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A72A72FF22321EE900B21995 /* SystemConfiguration.framework */; };
 		A72A730022321EE900B21995 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A72A72FF22321EE900B21995 /* SystemConfiguration.framework */; };
 		A72A730222321EEE00B21995 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A72A730122321EEE00B21995 /* libz.tbd */; };
 		A72A730222321EEE00B21995 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A72A730122321EEE00B21995 /* libz.tbd */; };
 		A72A730422321EFA00B21995 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A72A730322321EFA00B21995 /* libc++.tbd */; };
 		A72A730422321EFA00B21995 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A72A730322321EFA00B21995 /* libc++.tbd */; };
-		A72A730C2232207700B21995 /* AppDelegate+UM.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A73082232207600B21995 /* AppDelegate+UM.swift */; };
 		A72A73142232475E00B21995 /* AlipayManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A73132232475E00B21995 /* AlipayManager.swift */; };
 		A72A73142232475E00B21995 /* AlipayManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A73132232475E00B21995 /* AlipayManager.swift */; };
 		A72A73162232481600B21995 /* WeChatpayManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A73152232481600B21995 /* WeChatpayManager.swift */; };
 		A72A73162232481600B21995 /* WeChatpayManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A73152232481600B21995 /* WeChatpayManager.swift */; };
 		A72A7333223256E100B21995 /* PayManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A7332223256E100B21995 /* PayManager.swift */; };
 		A72A7333223256E100B21995 /* PayManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72A7332223256E100B21995 /* PayManager.swift */; };
@@ -194,7 +193,6 @@
 		A72A72FF22321EE900B21995 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
 		A72A72FF22321EE900B21995 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
 		A72A730122321EEE00B21995 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
 		A72A730122321EEE00B21995 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
 		A72A730322321EFA00B21995 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
 		A72A730322321EFA00B21995 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
-		A72A73082232207600B21995 /* AppDelegate+UM.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AppDelegate+UM.swift"; sourceTree = "<group>"; };
 		A72A73132232475E00B21995 /* AlipayManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlipayManager.swift; sourceTree = "<group>"; };
 		A72A73132232475E00B21995 /* AlipayManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlipayManager.swift; sourceTree = "<group>"; };
 		A72A73152232481600B21995 /* WeChatpayManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeChatpayManager.swift; sourceTree = "<group>"; };
 		A72A73152232481600B21995 /* WeChatpayManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeChatpayManager.swift; sourceTree = "<group>"; };
 		A72A7332223256E100B21995 /* PayManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayManager.swift; sourceTree = "<group>"; };
 		A72A7332223256E100B21995 /* PayManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayManager.swift; sourceTree = "<group>"; };
@@ -673,7 +671,6 @@
 			children = (
 			children = (
 				A77F2C602231FB49001BD3F6 /* AppDelegate.swift */,
 				A77F2C602231FB49001BD3F6 /* AppDelegate.swift */,
 				A77F2CC2223203BA001BD3F6 /* AppDelegate+Window.swift */,
 				A77F2CC2223203BA001BD3F6 /* AppDelegate+Window.swift */,
-				A72A73082232207600B21995 /* AppDelegate+UM.swift */,
 				A72A733422325A4B00B21995 /* AppDelegate+HandleOpen.swift */,
 				A72A733422325A4B00B21995 /* AppDelegate+HandleOpen.swift */,
 			);
 			);
 			path = AppDelegate;
 			path = AppDelegate;
@@ -1234,7 +1231,6 @@
 				A72A72BD22321DE000B21995 /* Extension+UIColor.swift in Sources */,
 				A72A72BD22321DE000B21995 /* Extension+UIColor.swift in Sources */,
 				A77F2CC822320627001BD3F6 /* WRCustomNavigationBar.swift in Sources */,
 				A77F2CC822320627001BD3F6 /* WRCustomNavigationBar.swift in Sources */,
 				A72A72BC22321DE000B21995 /* Extension+UIAlertController.swift in Sources */,
 				A72A72BC22321DE000B21995 /* Extension+UIAlertController.swift in Sources */,
-				A72A730C2232207700B21995 /* AppDelegate+UM.swift in Sources */,
 				A72A72B122321DE000B21995 /* UIScrollView+MJRefreshEX.m in Sources */,
 				A72A72B122321DE000B21995 /* UIScrollView+MJRefreshEX.m in Sources */,
 				A7A97FDA2238FBAD0070F84D /* VerticalListSectionModel.swift in Sources */,
 				A7A97FDA2238FBAD0070F84D /* VerticalListSectionModel.swift in Sources */,
 				A72A72A522321DE000B21995 /* LBXScanLineAnimation.swift in Sources */,
 				A72A72A522321DE000B21995 /* LBXScanLineAnimation.swift in Sources */,

+ 29 - 0
RainbowPlanet/RainbowPlanet/AppDelegate/AppDelegate+HandleOpen.swift

@@ -42,5 +42,34 @@ extension AppDelegate {
         }
         }
         return result;
         return result;
     }
     }
+
+    //iOS10以下使用这两个方法接收通知,
+    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
+        //关闭友盟自带的弹出框
+        UMessage.setAutoAlert(true)
+        if #available(iOS 9.0, *)  {
+            if #available(iOS 10.0, *){
+            }else {
+                UMessage.didReceiveRemoteNotification(userInfo)
+                completionHandler(UIBackgroundFetchResult.newData);
+            }
+        }
+    }
+
+    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
+        //关闭友盟自带的弹出框
+        UMessage.setAutoAlert(true)
+        if #available(iOS 9.0, *)  {
+            if #available(iOS 10.0, *){
+            }else {
+                UMessage.didReceiveRemoteNotification(userInfo)
+            }
+        }
+    }
+
+    /// 获取设备的 DeviceToken
+    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
+        NXLLog(deviceToken.description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: ""))
+    }
 }
 }
 
 

+ 0 - 177
RainbowPlanet/RainbowPlanet/AppDelegate/AppDelegate+UM.swift

@@ -1,177 +0,0 @@
-//
-//  AppDelegate+UM.swift
-//  RainbowPlanet
-//
-//  Created by 南鑫林 on 2018/8/1.
-//  Copyright © 2018年 南鑫林. All rights reserved.
-//
-
-import Foundation
-import AVFoundation
-
-var _entity : UMessageRegisterEntity?
-
-extension AppDelegate {
-    
-    /// 友盟初始化
-    func initUM(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
-
-        //公共
-        common()
-        //推送
-        push(launchOptions: launchOptions)
-        //分享
-        UMManager.shared().share()
-        
-    }
-    
-    ///公共
-    func common() -> Void {
-
-        //将自动采集页面信息
-//        MobClick.setAutoPageEnabled(true)
-        //开发者需要显式的调用此函数,日志系统才能工作
-        UMCommonLogManager.setUp()
-        //打开加密传输
-        UMConfigure.setEncryptEnabled(true)
-        //设置打开日志
-        UMConfigure.setLogEnabled(true)
-        //设置Key
-        UMConfigure.initWithAppkey(kUMengAppKey, channel: "App Store")
-
-        //开启Crash收集
-        MobClick.setCrashReportEnabled(true)
-        //默认为普通应用场景,目前还支持游戏统计场景
-        MobClick.setScenarioType(eScenarioType.E_UM_NORMAL)
-        //获得集成测试需要device_id
-        let deice_id = UMConfigure.deviceIDForIntegration()
-        if deice_id != nil {
-            print("服务器端成功返回deviceID:\(deice_id!)");
-        }else {
-            print("服务器端还没有返回deviceID");
-        }
-    }
-    
-    ///推送
-    func push(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
-        
-        _entity = UMessageRegisterEntity.init()
-        //type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
-        _entity?.types = Int(UInt8(UMessageAuthorizationOptions.badge.rawValue)|UInt8(UMessageAuthorizationOptions.alert.rawValue)|UInt8(UMessageAuthorizationOptions.sound.rawValue))
-        
-        if #available(iOS 8.0, *) {
-            if #available(iOS 10.0, *) {
-                
-                let action1_ios10 = UNNotificationAction(identifier: "action1_identifier", title: "打开应用", options: UNNotificationActionOptions.foreground)
-                let action2_ios10 = UNNotificationAction(identifier: "action2_identifier", title: "忽略", options: UNNotificationActionOptions.foreground)
-                
-                let category1_ios10 = UNNotificationCategory(identifier: "category1", actions: [action1_ios10,action2_ios10], intentIdentifiers: [], options: UNNotificationCategoryOptions.customDismissAction)
-                //UNNotificationCategoryOptionNone
-                //UNNotificationCategoryOptionCustomDismissAction  清除通知被触发会走通知的代理方法
-                //UNNotificationCategoryOptionAllowInCarPlay       适用于行车模式
-                let categories = NSSet(objects: category1_ios10)
-                _entity?.categories = (categories as! Set<AnyHashable>)
-                UNUserNotificationCenter.current().delegate = self
-                
-            } else {
-                let action1 = UIMutableUserNotificationAction.init()
-                action1.identifier = "action1_identifier"
-                action1.title = "打开应用"
-                action1.activationMode = UIUserNotificationActivationMode.foreground;//当点击的时候启动程序
-                
-                let action2 = UIMutableUserNotificationAction.init()
-                action2.identifier = "action2_identifier"
-                action2.title = "忽略"
-                action2.activationMode = UIUserNotificationActivationMode.background;//当点击的时候不启动程序,在后台处理
-                action2.isAuthenticationRequired = true;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
-                action2.isDestructive = true;
-                
-                let actionCategory1 = UIMutableUserNotificationCategory.init()
-                actionCategory1.identifier = "category1"//这组动作的唯一标示
-                actionCategory1.setActions([action1,action2], for: UIUserNotificationActionContext.default)
-                let categories = NSSet(objects: actionCategory1)
-                _entity?.categories = (categories as! Set<AnyHashable>)
-
-            }
-        }
-
-        UMessage.registerForRemoteNotifications(launchOptions: launchOptions, entity: _entity) { (granted, error) in
-
-            if granted {
-                
-            }else {
-                
-            }
-        }
-        UMessage.setBadgeClear(true)//设置是否允许SDK自动清空角标
-    }
-}
-
-
-@available(iOS 10.0, *)
-
-// MARK: - UNUserNotificationCenterDelegate
-extension AppDelegate:UNUserNotificationCenterDelegate {
-    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
-        let userInfo = notification.request.content.userInfo
-        
-        if (notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
-            UMessage.setAutoAlert(true)
-            //应用处于前台时的远程推送接受
-            //必须加这句代码
-            UMessage.didReceiveRemoteNotification(userInfo)
-
-        }else {
-            //应用处于前台时的本地推送接受
-        }
-        completionHandler(UNNotificationPresentationOptions(rawValue: UNNotificationPresentationOptions.sound.rawValue|UNNotificationPresentationOptions.alert.rawValue|UNNotificationPresentationOptions.badge.rawValue))
-    }
-    
-    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
-        let userInfo = response.notification.request.content.userInfo
-        if (response.notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
-            UMessage.setAutoAlert(true)
-            //应用处于前台时的远程推送接受
-            //必须加这句代码
-            UMessage.didReceiveRemoteNotification(userInfo)
-        }else {
-            //应用处于前台时的本地推送接受
-        }
-
-
-    }
-
-}
-
-// MARK: - 接受通知
-extension AppDelegate {
-    
-    //iOS10以下使用这两个方法接收通知,
-    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
-        //关闭友盟自带的弹出框
-        UMessage.setAutoAlert(true)
-        if #available(iOS 9.0, *)  {
-            if #available(iOS 10.0, *){
-            }else {
-                UMessage.didReceiveRemoteNotification(userInfo)
-                completionHandler(UIBackgroundFetchResult.newData);
-            }
-        }
-    }
-    
-    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
-        //关闭友盟自带的弹出框
-        UMessage.setAutoAlert(true)
-        if #available(iOS 9.0, *)  {
-            if #available(iOS 10.0, *){
-            }else {
-                UMessage.didReceiveRemoteNotification(userInfo)
-            }
-        }
-    }
-
-    /// 获取设备的 DeviceToken
-    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
-        NXLLog(deviceToken.description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: ""))
-    }
-}

+ 1 - 1
RainbowPlanet/RainbowPlanet/AppDelegate/AppDelegate.swift

@@ -20,7 +20,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
         //初始化窗口
         //初始化窗口
         initWindow()
         initWindow()
         //初始化友盟
         //初始化友盟
-        initUM(launchOptions: launchOptions)
+        UMManager.shared().initUM(launchOptions: launchOptions)
         //初始化键盘
         //初始化键盘
         IQKeyboardManagerSwiftManager.shared().initIQKeyboardManagerSwift()
         IQKeyboardManagerSwiftManager.shared().initIQKeyboardManagerSwift()
         return true
         return true

+ 127 - 0
RainbowPlanet/RainbowPlanet/Manager/UMManager/UMManager.swift

@@ -14,6 +14,8 @@ enum ShareType {
     case webPage
     case webPage
 }
 }
 
 
+var _entity : UMessageRegisterEntity?
+
 class UMManager: NSObject {
 class UMManager: NSObject {
     private static let sharedInstance = UMManager()
     private static let sharedInstance = UMManager()
 
 
@@ -26,7 +28,98 @@ class UMManager: NSObject {
 
 
     private override init() {} // 私有化init方法
     private override init() {} // 私有化init方法
 
 
+    /// 友盟初始化
+    func initUM(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
+
+        //公共
+        common()
+        //推送
+        push(launchOptions: launchOptions)
+        //分享
+        share()
+
+    }
+
+    ///公共
+    func common() -> Void {
+
+        //将自动采集页面信息
+        //        MobClick.setAutoPageEnabled(true)
+        //开发者需要显式的调用此函数,日志系统才能工作
+        UMCommonLogManager.setUp()
+        //打开加密传输
+        UMConfigure.setEncryptEnabled(true)
+        //设置打开日志
+        UMConfigure.setLogEnabled(true)
+        //设置Key
+        UMConfigure.initWithAppkey(kUMengAppKey, channel: "App Store")
+
+        //开启Crash收集
+        MobClick.setCrashReportEnabled(true)
+        //默认为普通应用场景,目前还支持游戏统计场景
+        MobClick.setScenarioType(eScenarioType.E_UM_NORMAL)
+        //获得集成测试需要device_id
+        let deice_id = UMConfigure.deviceIDForIntegration()
+        if deice_id != nil {
+            NXLLog("服务器端成功返回deviceID:\(deice_id!)");
+        }else {
+            NXLLog("服务器端还没有返回deviceID");
+        }
+    }
+
+    ///推送
+    func push(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
 
 
+        _entity = UMessageRegisterEntity.init()
+        //type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
+        _entity?.types = Int(UInt8(UMessageAuthorizationOptions.badge.rawValue)|UInt8(UMessageAuthorizationOptions.alert.rawValue)|UInt8(UMessageAuthorizationOptions.sound.rawValue))
+
+        if #available(iOS 8.0, *) {
+            if #available(iOS 10.0, *) {
+
+                let action1_ios10 = UNNotificationAction(identifier: "action1_identifier", title: "打开应用", options: UNNotificationActionOptions.foreground)
+                let action2_ios10 = UNNotificationAction(identifier: "action2_identifier", title: "忽略", options: UNNotificationActionOptions.foreground)
+
+                let category1_ios10 = UNNotificationCategory(identifier: "category1", actions: [action1_ios10,action2_ios10], intentIdentifiers: [], options: UNNotificationCategoryOptions.customDismissAction)
+                //UNNotificationCategoryOptionNone
+                //UNNotificationCategoryOptionCustomDismissAction  清除通知被触发会走通知的代理方法
+                //UNNotificationCategoryOptionAllowInCarPlay       适用于行车模式
+                let categories = NSSet(objects: category1_ios10)
+                _entity?.categories = (categories as! Set<AnyHashable>)
+                UNUserNotificationCenter.current().delegate = self
+
+            } else {
+                let action1 = UIMutableUserNotificationAction.init()
+                action1.identifier = "action1_identifier"
+                action1.title = "打开应用"
+                action1.activationMode = UIUserNotificationActivationMode.foreground;//当点击的时候启动程序
+
+                let action2 = UIMutableUserNotificationAction.init()
+                action2.identifier = "action2_identifier"
+                action2.title = "忽略"
+                action2.activationMode = UIUserNotificationActivationMode.background;//当点击的时候不启动程序,在后台处理
+                action2.isAuthenticationRequired = true;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
+                action2.isDestructive = true;
+
+                let actionCategory1 = UIMutableUserNotificationCategory.init()
+                actionCategory1.identifier = "category1"//这组动作的唯一标示
+                actionCategory1.setActions([action1,action2], for: UIUserNotificationActionContext.default)
+                let categories = NSSet(objects: actionCategory1)
+                _entity?.categories = (categories as! Set<AnyHashable>)
+
+            }
+        }
+
+        UMessage.registerForRemoteNotifications(launchOptions: launchOptions, entity: _entity) { (granted, error) in
+
+            if granted {
+
+            }else {
+
+            }
+        }
+        UMessage.setBadgeClear(true)//设置是否允许SDK自动清空角标
+    }
     /// 分享设置
     /// 分享设置
     func share() -> Void {
     func share() -> Void {
         /*
         /*
@@ -224,3 +317,37 @@ class UMManager: NSObject {
     }
     }
 }
 }
 
 
+@available(iOS 10.0, *)
+
+// MARK: - UNUserNotificationCenterDelegate
+extension UMManager:UNUserNotificationCenterDelegate {
+    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
+        let userInfo = notification.request.content.userInfo
+
+        if (notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
+            UMessage.setAutoAlert(true)
+            //应用处于前台时的远程推送接受
+            //必须加这句代码
+            UMessage.didReceiveRemoteNotification(userInfo)
+
+        }else {
+            //应用处于前台时的本地推送接受
+        }
+        completionHandler(UNNotificationPresentationOptions(rawValue: UNNotificationPresentationOptions.sound.rawValue|UNNotificationPresentationOptions.alert.rawValue|UNNotificationPresentationOptions.badge.rawValue))
+    }
+
+    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
+        let userInfo = response.notification.request.content.userInfo
+        if (response.notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))! {
+            UMessage.setAutoAlert(true)
+            //应用处于前台时的远程推送接受
+            //必须加这句代码
+            UMessage.didReceiveRemoteNotification(userInfo)
+        }else {
+            //应用处于前台时的本地推送接受
+        }
+
+
+    }
+
+}