Quellcode durchsuchen

路由调试完成

南鑫林 vor 5 Jahren
Ursprung
Commit
10cf6938d3

BIN
.DS_Store


+ 23 - 3
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -194,6 +194,9 @@
 		A76390EB2248E27A0067EEE0 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A76390EA2248E27A0067EEE0 /* UserNotifications.framework */; };
 		A7649B6922977A4300BCE9D1 /* ShopSectionHeaderModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7649B6822977A4300BCE9D1 /* ShopSectionHeaderModel.swift */; };
 		A76B786922CE04940047EC1B /* CommunityRecommendDetailHTMLTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A76B786822CE04940047EC1B /* CommunityRecommendDetailHTMLTableViewCell.swift */; };
+		A770E5DB22CED8C600CBD0A4 /* RouterManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A770E5DA22CED8C600CBD0A4 /* RouterManager.swift */; };
+		A770E5DD22CEDF4F00CBD0A4 /* OpenAppModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A770E5DC22CEDF4F00CBD0A4 /* OpenAppModel.swift */; };
+		A770E5E022CF19FA00CBD0A4 /* CommunityRouterModuleType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A770E5DF22CF19FA00CBD0A4 /* CommunityRouterModuleType.swift */; };
 		A771F07C226D4E1C007999DB /* AddressPOITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A771F07B226D4E1C007999DB /* AddressPOITableViewCell.swift */; };
 		A773D02F229FDC3B007A5751 /* DIYEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A773D02E229FDC3B007A5751 /* DIYEmptyView.swift */; };
 		A775CBFE2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A775CBFD2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift */; };
@@ -870,6 +873,9 @@
 		A76390EA2248E27A0067EEE0 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
 		A7649B6822977A4300BCE9D1 /* ShopSectionHeaderModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShopSectionHeaderModel.swift; sourceTree = "<group>"; };
 		A76B786822CE04940047EC1B /* CommunityRecommendDetailHTMLTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityRecommendDetailHTMLTableViewCell.swift; sourceTree = "<group>"; };
+		A770E5DA22CED8C600CBD0A4 /* RouterManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouterManager.swift; sourceTree = "<group>"; };
+		A770E5DC22CEDF4F00CBD0A4 /* OpenAppModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenAppModel.swift; sourceTree = "<group>"; };
+		A770E5DF22CF19FA00CBD0A4 /* CommunityRouterModuleType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityRouterModuleType.swift; sourceTree = "<group>"; };
 		A771F07B226D4E1C007999DB /* AddressPOITableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressPOITableViewCell.swift; sourceTree = "<group>"; };
 		A773D02E229FDC3B007A5751 /* DIYEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DIYEmptyView.swift; sourceTree = "<group>"; };
 		A775CBFD2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingMallNavigationBarView.swift; sourceTree = "<group>"; };
@@ -2246,7 +2252,6 @@
 		A72A725422321B9400B21995 /* Manager */ = {
 			isa = PBXGroup;
 			children = (
-				A7AA9FA422C895650086498B /* RouteManner */,
 				A797FDE922C5AC570076DCB3 /* CacheManager */,
 				A7D5F24E22BC7B0500F8E9AF /* WebViewJavascriptBridgeManager */,
 				A73911AB229CD6080033177E /* AlamofireReachabilityManager */,
@@ -2460,6 +2465,7 @@
 		A738D203225AEAD000EEE860 /* Model */ = {
 			isa = PBXGroup;
 			children = (
+				A770E5DE22CEDF5700CBD0A4 /* OpenAppModel */,
 				A72A73722233966800B21995 /* RootModel */,
 				A7AA9F5B22C5FCE50086498B /* VirusModel */,
 				A7D5F25D22C0612A00F8E9AF /* CommunityModel */,
@@ -2660,6 +2666,14 @@
 			path = View;
 			sourceTree = "<group>";
 		};
+		A770E5DE22CEDF5700CBD0A4 /* OpenAppModel */ = {
+			isa = PBXGroup;
+			children = (
+				A770E5DC22CEDF4F00CBD0A4 /* OpenAppModel.swift */,
+			);
+			path = OpenAppModel;
+			sourceTree = "<group>";
+		};
 		A773D02D229FD5B7007A5751 /* MainView */ = {
 			isa = PBXGroup;
 			children = (
@@ -2821,6 +2835,7 @@
 				A71CAB3F22CB32A300D908A8 /* ViewModel */,
 				A738D203225AEAD000EEE860 /* Model */,
 				A72A7252223219BD00B21995 /* Service */,
+				A7AA9FA422C895650086498B /* Router */,
 				A72A725422321B9400B21995 /* Manager */,
 				A72A725922321C5E00B21995 /* Macro */,
 				A77F2CBC2232022A001BD3F6 /* Tools */,
@@ -3366,11 +3381,13 @@
 			path = Recommend;
 			sourceTree = "<group>";
 		};
-		A7AA9FA422C895650086498B /* RouteManner */ = {
+		A7AA9FA422C895650086498B /* Router */ = {
 			isa = PBXGroup;
 			children = (
+				A770E5DA22CED8C600CBD0A4 /* RouterManager.swift */,
+				A770E5DF22CF19FA00CBD0A4 /* CommunityRouterModuleType.swift */,
 			);
-			path = RouteManner;
+			path = Router;
 			sourceTree = "<group>";
 		};
 		A7B4E71B22812D390012914A /* ShoppingMallSlidingLeftRight */ = {
@@ -5696,6 +5713,7 @@
 				BD20F1D52283D15500677D8E /* OrderFinishPayFailureCell.swift in Sources */,
 				A72A72C022321DE000B21995 /* Extension+UIView.swift in Sources */,
 				BDAF83B022B3B63B0004BCC3 /* RecommendCommentHeader.swift in Sources */,
+				A770E5DD22CEDF4F00CBD0A4 /* OpenAppModel.swift in Sources */,
 				BD7AB83A2284288D0030646A /* ShoppingCartPayOrderFooter.swift in Sources */,
 				A719EE6E22AF441F001AAC98 /* CommunityViewController.swift in Sources */,
 				BD13B6C622BA034D008BB323 /* PublishEditTitleCell.swift in Sources */,
@@ -5727,6 +5745,7 @@
 				BDF47D7E22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift in Sources */,
 				BD108C9522A60C2100837DAB /* HGImageCollectionViewCell.swift in Sources */,
 				A7FF1589228C854900A85748 /* OrderDetailBottomView.swift in Sources */,
+				A770E5DB22CED8C600CBD0A4 /* RouterManager.swift in Sources */,
 				BD1FC1A722B1075F00D55081 /* UIColor+Expanded.m in Sources */,
 				A7D5F22B22BB687100F8E9AF /* BaseJSWebViewController.swift in Sources */,
 				BD1DC6C5228CFD0B00B89C57 /* SwiftMoyaNetWorkServiceOrder.swift in Sources */,
@@ -6234,6 +6253,7 @@
 				A757849F22C1CEA900D4DB61 /* FollowStatusModel.swift in Sources */,
 				A7CC751F227190C5003C4F38 /* AccountSecurityViewController.swift in Sources */,
 				BD13B6C422BA034D008BB323 /* PublishEditDefaultCollectionCell.swift in Sources */,
+				A770E5E022CF19FA00CBD0A4 /* CommunityRouterModuleType.swift in Sources */,
 				BD29A92E228F99780018CFC3 /* OrderCommentParameterModel.swift in Sources */,
 				BD61230522C36C6900D3F513 /* AlivcPushBeautyDataManager.m in Sources */,
 				A7284440224DFACD00F82F30 /* InfoModel.swift in Sources */,

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

@@ -17,6 +17,11 @@ extension AppDelegate {
         if (!result) {
             // 其他如支付等SDK的回调
             result = PayManager.shared().handleOpen(url: url)
+            if !result {
+                // 自己路由
+                result = RouterManager.shared.handleOpen(url: url)
+                return result
+            }
             return result
         }
         return result;
@@ -27,6 +32,11 @@ extension AppDelegate {
         if (!result) {
             // 其他如支付等SDK的回调
             result = PayManager.shared().handleOpen(url: url)
+            if !result {
+                // 自己路由
+                result = RouterManager.shared.handleOpen(url: url)
+                return result
+            }
             return result
         }
         return result;

+ 47 - 0
RainbowPlanet/RainbowPlanet/Macro/Common.swift

@@ -299,3 +299,50 @@ func getImageHeight(imgStr:String) -> CGFloat {
 //    NXLLog(heightFloat)
     return heightFloat/2
 }
+
+/// url字符串转字典
+///
+/// - Parameter urlString: urlString字符串
+/// - Returns: [String: Any]
+public func urlStringtoParams(_ urlString:String) -> [String: Any] {
+    // 1 保存参数
+    var url_array = [""]
+    // 2 内容中是否存在?或者//
+    if urlString.contains("?") {
+        url_array = urlString.components(separatedBy:"?")
+    }else{
+        url_array = urlString.components(separatedBy: "//")
+    }
+    // 3 多个参数,分割参数
+    let urlComponents = url_array[1].components(separatedBy: "&")
+    // 4 保存返回值
+    var params = [String: Any]()
+    // 5 遍历参数
+    for keyValuePair in urlComponents {
+        // 5.1 分割参数 生成Key/Value
+        let pairComponents = keyValuePair.components(separatedBy:"=")
+        // 5.2 获取数组首元素作为key
+        let key = pairComponents.first?.removingPercentEncoding
+        // 5.3 获取数组末元素作为value
+        let value = pairComponents.last?.removingPercentEncoding
+        // 5.4 判断参数是否是数组
+        if let key = key, let value = value {
+            // 5.5 已存在的值,生成数组
+            if let existValue = params[key] {
+                // 5.8 如果是已经生成的数组
+                if var existValue = existValue as? [Any] {
+                    // 5.9 把新的值添加到已经生成的数组中去
+                    existValue.append(value)
+                    params[key] = existValue
+                } else {
+                    // 5.7 已存在的值,先将他生成数组
+                    params[key] = [existValue, value]
+                }
+            } else {
+                // 5.6 参数是非数组
+                params[key] = value
+            }
+        }
+    }
+    return params
+}

+ 30 - 0
RainbowPlanet/RainbowPlanet/Model/OpenAppModel/OpenAppModel.swift

@@ -0,0 +1,30 @@
+//
+//	OpenAppModel.swift
+//	Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport
+
+import Foundation 
+import ObjectMapper
+
+
+class OpenAppModel : NSObject, Mappable{
+
+	var postId : String?
+	var postType : String?
+	var type : String?
+
+
+	class func newInstance(map: Map) -> Mappable?{
+		return OpenAppModel()
+	}
+	required init?(map: Map){}
+	private override init(){}
+
+	func mapping(map: Map)
+	{
+		postId <- map["post_id"]
+		postType <- map["post_type"]
+		type <- map["type"]
+		
+	}
+
+}

+ 34 - 0
RainbowPlanet/RainbowPlanet/Router/CommunityRouterModuleType.swift

@@ -0,0 +1,34 @@
+//
+//  CommunityRouterModuleType.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/7/5.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import SwiftyMediator
+
+/// 社区模块的
+///
+/// - pushPostDetailContent: 跳转帖子内容
+/// - pushPostDetailVoide: 跳转视频内容
+public enum CommunityRouterModuleType: MediatorTargetType {
+    case pushPostDetailContent(postId: String)
+    case pushPostDetailVoide(postId: String)
+}
+
+extension CommunityRouterModuleType: MediatorSourceType {
+    public var viewController: UIViewController? {
+        switch self {
+        case .pushPostDetailContent(let postId):
+            let vc = CommunityRecommendController()
+            vc.id = Int(postId) ?? 0
+            return vc
+        case .pushPostDetailVoide(let postId):
+            let vc = CommunityVideoListController()
+            vc.contentId = Int(postId) ?? 0
+            return vc
+        }
+    }
+}

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

@@ -0,0 +1,43 @@
+//
+//  RouterManner.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/7/5.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import SwiftyMediator
+
+
+
+
+class RouterManager: NSObject {
+    static let shared : RouterManager = RouterManager()
+    
+    /// 打开App
+    ///
+    /// - Parameter url:
+    /// - Returns:
+    func handleOpen(url:URL) -> Bool {
+        
+        if url.host == "home" { //社区
+            let dict = urlStringtoParams(url.absoluteString)
+            let openAppModel = OpenAppModel(JSON: dict)
+            if openAppModel?.postId != nil {
+                switch PostType(rawValue: openAppModel?.postType ?? "image") {
+                case .image?,.html?:
+                    Mediator.push(CommunityRouterModuleType.pushPostDetailContent(postId: openAppModel?.postId ?? "0"))
+                    break
+                case .video?:
+                    Mediator.push(CommunityRouterModuleType.pushPostDetailVoide(postId: openAppModel?.postId ?? "0"))
+                    break
+                default:
+                    break
+                }
+            }
+            return true
+        }
+        return false
+    }
+}