Procházet zdrojové kódy

友盟推送完成

南鑫林 před 5 roky
rodič
revize
e661bfbfc6

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

@@ -172,6 +172,8 @@
 		A739121A229F75F50033177E /* JXPagingMainTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7391213229F75F50033177E /* JXPagingMainTableView.swift */; };
 		A739121B229F75F50033177E /* JXPagingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7391214229F75F50033177E /* JXPagingView.swift */; };
 		A739121D229F75F50033177E /* JXPagingListContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7391216229F75F50033177E /* JXPagingListContainerView.swift */; };
+		A73A56D322DC59A3004920FE /* PushModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A73A56D222DC59A3004920FE /* PushModel.swift */; };
+		A73A56D522DC5E34004920FE /* UMPushRouterModuleType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A73A56D422DC5E34004920FE /* UMPushRouterModuleType.swift */; };
 		A73D7C682268A032002A4CE3 /* SwiftyStarRatingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A73D7C672268A032002A4CE3 /* SwiftyStarRatingView.swift */; };
 		A743229422B88ED30017C367 /* EnumMacro.swift in Sources */ = {isa = PBXBuildFile; fileRef = A743229322B88ED30017C367 /* EnumMacro.swift */; };
 		A743229B22B8C1510017C367 /* AppStoreReview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A743229A22B8C1510017C367 /* AppStoreReview.swift */; };
@@ -852,6 +854,8 @@
 		A7391213229F75F50033177E /* JXPagingMainTableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JXPagingMainTableView.swift; sourceTree = "<group>"; };
 		A7391214229F75F50033177E /* JXPagingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JXPagingView.swift; sourceTree = "<group>"; };
 		A7391216229F75F50033177E /* JXPagingListContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JXPagingListContainerView.swift; sourceTree = "<group>"; };
+		A73A56D222DC59A3004920FE /* PushModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushModel.swift; sourceTree = "<group>"; };
+		A73A56D422DC5E34004920FE /* UMPushRouterModuleType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UMPushRouterModuleType.swift; sourceTree = "<group>"; };
 		A73D7C672268A032002A4CE3 /* SwiftyStarRatingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyStarRatingView.swift; sourceTree = "<group>"; };
 		A743229322B88ED30017C367 /* EnumMacro.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumMacro.swift; sourceTree = "<group>"; };
 		A743229A22B8C1510017C367 /* AppStoreReview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStoreReview.swift; sourceTree = "<group>"; };
@@ -2457,6 +2461,7 @@
 		A738D203225AEAD000EEE860 /* Model */ = {
 			isa = PBXGroup;
 			children = (
+				A73A56D122DC598F004920FE /* PushModel */,
 				A770E5DE22CEDF5700CBD0A4 /* OpenAppModel */,
 				A72A73722233966800B21995 /* RootModel */,
 				A7AA9F5B22C5FCE50086498B /* VirusModel */,
@@ -2490,6 +2495,14 @@
 			path = "JXPagingView-Swift";
 			sourceTree = "<group>";
 		};
+		A73A56D122DC598F004920FE /* PushModel */ = {
+			isa = PBXGroup;
+			children = (
+				A73A56D222DC59A3004920FE /* PushModel.swift */,
+			);
+			path = PushModel;
+			sourceTree = "<group>";
+		};
 		A73D7C662268A032002A4CE3 /* SwiftyStarRatingView */ = {
 			isa = PBXGroup;
 			children = (
@@ -3461,6 +3474,7 @@
 				A7DAB33222D881F5005B964E /* H5RouterModuleType.swift */,
 				A7DAB33422D8D3AC005B964E /* RegisterLoginRouterModuleType.swift */,
 				A7DAB33822DC2B83005B964E /* ShareRouterModuleType.swift */,
+				A73A56D422DC5E34004920FE /* UMPushRouterModuleType.swift */,
 			);
 			path = Router;
 			sourceTree = "<group>";
@@ -5844,6 +5858,7 @@
 				A7BB68672269B1DD00AB07A2 /* AddressPOIViewController.swift in Sources */,
 				A7284A7322546460000BAEC4 /* SwiftMoyaServicePayApi.swift in Sources */,
 				BDE3045D22851E4F001D050F /* ProductCartListModel.swift in Sources */,
+				A73A56D322DC59A3004920FE /* PushModel.swift in Sources */,
 				BD12B68822B4F28F00AEB10B /* KSExtension.swift in Sources */,
 				BD61229322C3605C00D3F513 /* AliyunEffectResourceModel.m in Sources */,
 				A7A98DFF227E8501005306E9 /* SwiftMoyaNetWorkServiceProduct.swift in Sources */,
@@ -6232,6 +6247,7 @@
 				A71CAB4122CB32C700D908A8 /* VirusViewModel.swift in Sources */,
 				A7FF1572228C7D4600A85748 /* OrderButtonTableViewCell.swift in Sources */,
 				BD61226122C3561C00D3F513 /* MagicCameraPressCircleView.m in Sources */,
+				A73A56D522DC5E34004920FE /* UMPushRouterModuleType.swift in Sources */,
 				A7B4E72F2281773F0012914A /* ProductFloorCenterTitleView.swift in Sources */,
 				A7AA9F5822C5F6150086498B /* SwiftMoyaServiceVirusApi.swift in Sources */,
 				A7284A542252FB5C000BAEC4 /* PaginationModel.swift in Sources */,

+ 5 - 2
RainbowPlanet/RainbowPlanet/AppDelegate/AppDelegate+HandleOpen.swift

@@ -45,14 +45,17 @@ extension AppDelegate {
     //iOS10以下使用这两个方法接收通知,
     func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
         //关闭友盟自带的弹出框
-        UMessage.setAutoAlert(true)
+        UMessage.setAutoAlert(false)
         UMessage.didReceiveRemoteNotification(userInfo)
+        RouterManager.shared.UMPush(pushModel: PushModel(JSONString: userInfo.description) ?? PushModel())
         completionHandler(UIBackgroundFetchResult.newData);
     }
 
     func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
         //关闭友盟自带的弹出框
-        UMessage.setAutoAlert(true)
+        UMessage.setAutoAlert(false)
+        RouterManager.shared.UMPush(pushModel: PushModel(JSONString: userInfo.description) ?? PushModel())
+
         // 接受笑死通知
         UMessage.didReceiveRemoteNotification(userInfo)
     }

+ 11 - 11
RainbowPlanet/RainbowPlanet/Base/BaseTabbarViewController/BaseTabbarViewController.swift

@@ -12,21 +12,21 @@ class BaseTabbarViewController: UITabBarController {
     
     static let shared : BaseTabbarViewController = BaseTabbarViewController()
     
+    /// 社区
+    let v1 = CommunityViewController()
+    /// 商城
+    let v2 = ShoppingMallViewController()
+    /// 发布
+    let v3 = BaseViewController()
+    /// 消息
+    let v4 = MessageMainViewController()
+    /// 我的
+    let v5 = UserPersonalCenterViewController()
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         self.tabBar.shadowImage = UIImage(named: "tab_top_line")
         self.delegate = self
-        /// 社区
-        let v1 = CommunityViewController()
-        /// 商城
-        let v2 = ShoppingMallViewController()
-        /// 发布
-        let v3 = BaseViewController()
-        /// 消息
-        let v4 = MessageMainViewController()
-        /// 我的
-        let v5 = UserPersonalCenterViewController()
-
         
         tabBarItemStyle(vc: v1, normalImg: "tabbar_home", selectorImg: "tabbar_home_pre", title: "社区")
         v1.tabBarItem.tag = 0

+ 3 - 3
RainbowPlanet/RainbowPlanet/Macro/Common.swift

@@ -131,11 +131,11 @@ func delay(by delayTime: TimeInterval, qosClass: DispatchQoS.QoSClass? = nil,
     dispatchQueue.asyncAfter(deadline: DispatchTime.now() + delayTime, execute: closure)
 }
 
-func getCurrentVC() -> UIViewController {
+func getCurrentVC() -> UIViewController? {
     let keywindow = (UIApplication.shared.delegate as! AppDelegate).window
     let firstView: UIView = (keywindow?.subviews.first)!
     let secondView: UIView = firstView.subviews.first!
-    var vc = viewForController(view: secondView)!
+    var vc = viewForController(view: secondView)
     vc = ((vc as! UITabBarController).selectedViewController! as! UINavigationController).visibleViewController!
 
     return vc
@@ -154,7 +154,7 @@ private func viewForController(view:UIView)->UIViewController?{
 
 //classType: 当前页面类类型
 func vcResult(classType: UIViewController.Type) -> Bool {
-    return getCurrentVC().isKind(of: classType)
+    return (getCurrentVC()?.isKind(of: classType))!
 }
 
 

+ 2 - 1
RainbowPlanet/RainbowPlanet/Macro/EnumMacro.swift

@@ -162,7 +162,8 @@ enum CommunityFollowType : String {
 /// - image: 图片
 /// - video: 视频
 /// - html: 富文本
-enum PostType : String{    
+enum PostType : String{
+    case none = ""
     case image = "image"
     case video = "video"
     case html = "html"

+ 43 - 34
RainbowPlanet/RainbowPlanet/Manager/UMManager/UMManager.swift

@@ -7,6 +7,7 @@
 //
 
 import UIKit
+import SwiftyJSON
 
 //MARK: - UMeng
 let kUMengAppKey  = "5c984a7f0cafb2332300000f"
@@ -80,6 +81,10 @@ public extension UMManager {
     ///推送
     func push(launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Void {
 
+        UMessage.openDebugMode(true)
+        UMessage.setBadgeClear(true)//设置是否允许SDK自动清空角标
+        UMessage.setWebViewClassString("UMWebViewController")
+        UMessage.addLaunch() //开屏图
         _entity = UMessageRegisterEntity.init()
         //type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
         _entity?.types = Int(UInt8(UMessageAuthorizationOptions.badge.rawValue)|UInt8(UMessageAuthorizationOptions.alert.rawValue)|UInt8(UMessageAuthorizationOptions.sound.rawValue))
@@ -127,10 +132,6 @@ public extension UMManager {
 
             }
         }
-        UMessage.setBadgeClear(true)//设置是否允许SDK自动清空角标
-        UMessage.openDebugMode(true)
-        UMessage.setWebViewClassString("UMWebViewController")
-        UMessage.addLaunch() //开屏图
     }
     
     /// 添加别名
@@ -150,6 +151,44 @@ public extension UMManager {
     
 }
 
+@available(iOS 10.0, *)
+// MARK: - UNUserNotificationCenterDelegate
+extension UMManager:UNUserNotificationCenterDelegate {
+    public 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(false)
+            //应用处于前台时的远程推送接受
+            let json = JSON(userInfo)
+            RouterManager.shared.UMPush(pushModel: PushModel(JSONString: json.description) ?? PushModel())
+            //必须加这句代码
+            UMessage.didReceiveRemoteNotification(userInfo)
+            
+        }else {
+            //应用处于前台时的本地推送接受
+        }
+        completionHandler(UNNotificationPresentationOptions(rawValue: UNNotificationPresentationOptions.sound.rawValue|UNNotificationPresentationOptions.alert.rawValue|UNNotificationPresentationOptions.badge.rawValue))
+    }
+    
+    public 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(false)
+            //应用处于后台时的远程推送接受
+            let json = JSON(userInfo)
+            RouterManager.shared.UMPush(pushModel: PushModel(JSONString: json.description) ?? PushModel())
+
+            //必须加这句代码
+            UMessage.didReceiveRemoteNotification(userInfo)
+            
+        }else {
+            //应用处于前台时的本地推送接受
+        }
+    }
+}
+
+
 // MARK: 分享
 public extension UMManager {
     /// 分享设置
@@ -386,33 +425,3 @@ extension UMManager {
 }
 
 
-@available(iOS 10.0, *)
-// MARK: - UNUserNotificationCenterDelegate
-extension UMManager:UNUserNotificationCenterDelegate {
-    public 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))
-    }
-
-    public 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 {
-            //应用处于前台时的本地推送接受
-        }
-    }
-}

+ 111 - 0
RainbowPlanet/RainbowPlanet/Model/PushModel/PushModel.swift

@@ -0,0 +1,111 @@
+//
+//	PushModel.swift
+//	Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport
+
+import Foundation 
+import ObjectMapper
+
+
+/// 推送跳转
+///
+/// - none: 不跳转
+/// - post: 跳转到帖子详情
+/// - recommend: 跳转到推荐首页
+/// - star:  跳转到星球首页
+enum PushActionType : String {
+    case none = ""
+    case post = "post"
+    case recommend = "recommend"
+    case star = "star"
+}
+
+class PushModel : NSObject, Mappable{
+
+    
+    /// 自定义
+    /// 跳转类型
+    var actionType : String? {
+        didSet {
+            pushActionType = PushActionType(rawValue: actionType ?? "")
+        }
+    }
+    var pushActionType : PushActionType?
+    // 帖子类型
+    var postType : String? {
+        didSet {
+            pushPostType = PostType(rawValue: postType ?? "")
+
+        }
+    }
+    var pushPostType : PostType?
+    // 动作Id
+    var actionId : Int?
+	
+    //系统
+	var aps : PushAp?
+	var d : String?
+	var p : Int?
+    
+
+
+	class func newInstance(map: Map) -> Mappable?{
+		return PushModel()
+	}
+	required init?(map: Map){}
+    override init(){}
+
+	func mapping(map: Map)
+	{
+		actionId <- map["action_id"]
+		actionType <- map["action_type"]
+        postType <- map["post_type"]
+		aps <- map["aps"]
+		d <- map["d"]
+		p <- map["p"]
+		
+	}
+
+}
+
+class PushAp : NSObject, Mappable{
+    
+    var alert : PushAlert?
+    
+    class func newInstance(map: Map) -> Mappable?{
+        return PushAp()
+    }
+    required init?(map: Map){}
+    private override init(){}
+    
+    func mapping(map: Map)
+    {
+        alert <- map["alert"]
+        
+    }
+    
+}
+
+class PushAlert : NSObject, Mappable{
+    
+    var body : String?
+    var subtitle : String?
+    var title : String?
+    
+    
+    class func newInstance(map: Map) -> Mappable?{
+        return PushAlert()
+    }
+    required init?(map: Map){}
+    private override init(){}
+    
+    func mapping(map: Map)
+    {
+        body <- map["body"]
+        subtitle <- map["subtitle"]
+        title <- map["title"]
+        
+    }
+    
+}
+
+

+ 8 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Main/CommunityViewController.swift

@@ -289,6 +289,14 @@ class CommunityViewController: BaseViewController {
         self.listContainerView.defaultSelectedIndex = 1
         self.segmentedDataSource.reloadData(selectedIndex: 1)
 
+    }
+    //选中星球
+    func reloadSegmentedStarView() {
+        self.segmentedView.selectItemAt(index: 2)
+        self.segmentedView.defaultSelectedIndex = 2
+        self.listContainerView.defaultSelectedIndex = 2
+        self.segmentedDataSource.reloadData(selectedIndex: 2)
+        
     }
     /// navigationBar
     private lazy var communityNavigationBarView: CommunityNavigationBarView = {

+ 0 - 2
RainbowPlanet/RainbowPlanet/Router/H5RouterModuleType.swift

@@ -9,8 +9,6 @@
 import UIKit
 import SwiftyMediator
 
-/// H5RouterModuleType
-
 
 /// <#Description#>
 ///

+ 51 - 0
RainbowPlanet/RainbowPlanet/Router/RouterManager.swift

@@ -37,4 +37,55 @@ class RouterManager: NSObject {
         }
         return false
     }
+    
+    
+    /// 友盟推送跳转
+    ///
+    /// - Parameter pushModel: 推送的模型
+    func UMPush(pushModel:PushModel) {
+        switch pushModel.pushActionType {
+        case .post?:
+            switch pushModel.pushPostType {//图文帖子
+            case .image?,.html?:
+                Mediator.push(UMPushRouterModuleType.pushPostContent(id: pushModel.actionId ?? 0))
+                break
+            case .video?: //视频帖子
+                Mediator.push(UMPushRouterModuleType.pushVideoContent(id: pushModel.actionId ?? 0))
+                break
+            default:
+                break
+            }
+            break
+        case .recommend?: //推荐
+            let vc = UIViewController.topMost
+            let tabBarController = vc?.tabBarController as? BaseTabbarViewController
+            tabBarController?.v1.reloadSegmentedView()
+            tabBarController?.selectedIndex = 0
+            if vc?.presentingViewController != nil {
+                vc?.dismissToWindowRootViewController(animated: false, completion: {
+                    
+                })
+            } else {
+                vc?.navigationController?.popToRootViewController(animated: false)
+            }
+            break
+        case .star?:
+            let vc = UIViewController.topMost
+            let tabBarController = vc?.tabBarController as? BaseTabbarViewController
+            tabBarController?.v1.reloadSegmentedStarView()
+            tabBarController?.selectedIndex = 0
+            if vc?.presentingViewController != nil {
+                vc?.dismissToWindowRootViewController(animated: false, completion: {
+                    
+                })
+            } else {
+                vc?.navigationController?.popToRootViewController(animated: false)
+            }
+            break
+        case .none?:
+            break
+        default:
+            break
+        }
+    }
 }

+ 1 - 1
RainbowPlanet/RainbowPlanet/Router/ShareRouterModuleType.swift

@@ -11,7 +11,7 @@ import SwiftyMediator
 
 /// 分享模块路由
 ///
-/// - pushShareActivity: 邀请好友图片
+/// - pushShareActivity: 邀请好友
 public enum ShareRouterModuleType: MediatorTargetType {
     case pushShareActivity
 }

+ 35 - 0
RainbowPlanet/RainbowPlanet/Router/UMPushRouterModuleType.swift

@@ -0,0 +1,35 @@
+//
+//  PushRouterModuleType.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/7/15.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import SwiftyMediator
+
+/// 友盟推送
+///
+/// - pushPostContent: 帖子内容
+public enum UMPushRouterModuleType: MediatorTargetType {
+    case pushPostContent(id: Int)
+    case pushVideoContent(id: Int)
+}
+
+extension UMPushRouterModuleType: MediatorSourceType {
+    public var viewController: UIViewController? {
+        switch self {
+        case .pushPostContent(let id):
+            let vc = CommunityRecommendController()
+            vc.id = id
+            return vc
+        case .pushVideoContent(let id):
+            let vc = CommunityVideoListController()
+            vc.contentId = id
+            return vc
+        }
+    }
+}
+
+

+ 1 - 1
RainbowPlanet/RainbowPlanet/Tools/Extension/Extension+UIAlertController.swift

@@ -78,6 +78,6 @@ extension UIAlertController {
         alert.addAction(albumAction)
 
         let viewController = getCurrentVC()
-        viewController.present(alert, animated: true)
+        viewController?.present(alert, animated: true)
     }
 }

+ 2 - 3
RainbowPlanet/RainbowPlanet/Tools/PhotoAndCameraManager/PhotoAndCameraManager.swift

@@ -36,7 +36,7 @@ class PhotoAndCameraManager: NSObject {
                 picker.sourceType = UIImagePickerController.SourceType.photoLibrary
                 picker.delegate = strongSelf
                 picker.allowsEditing = strongSelf.isEditedImage
-                getCurrentVC().present(picker, animated: true, completion: nil)
+                getCurrentVC()?.present(picker, animated: true, completion: nil)
             } else {
                 LBXPermissions.jumpToSystemPrivacySetting()
             }
@@ -54,8 +54,7 @@ class PhotoAndCameraManager: NSObject {
                 picker.sourceType = UIImagePickerController.SourceType.camera
                 picker.delegate = strongSelf;
                 picker.allowsEditing = strongSelf.isEditedImage
-                
-                getCurrentVC().present(picker, animated: true, completion: nil)
+                getCurrentVC()?.present(picker, animated: true, completion: nil)
             } else {
                 LBXPermissions.jumpToSystemPrivacySetting()
             }