Last active
September 29, 2017 03:05
-
-
Save buoge/1454eee8066261ad51bd5788a2c6d348 to your computer and use it in GitHub Desktop.
LinkPage iOS 接入 swift3 服务注册代码,官方文档是旧的 swift2, xcode9 没法使用,希望可以帮助到其他小伙伴
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 一些配置,看官方文档就可以了,填写包信息,schemes信息 等等 | |
### application | |
// 判断是否是通过LinkedME的UrlScheme唤起App | |
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { | |
if url.absoluteString.components(separatedBy: "click_id").count > 1 { | |
return LinkedME.getInstance().handleDeepLink(url); | |
} | |
return true | |
} | |
// URIScheme启动App | |
func application(_ application: UIApplication, open url: URL,sourceApplication: String?, | |
annotation: Any) -> Bool { | |
//判断是否是通过LinkedME的UrlScheme唤起App | |
if url.absoluteString.components(separatedBy: "click_id").count > 1 { | |
return LinkedME.getInstance().handleDeepLink(url); | |
} | |
return true | |
} | |
// UniversalLinks启动App | |
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Swift.Void) -> Bool{ | |
//判断是否是通过LinkedME的Universal Links唤起App | |
if let url = userActivity.webpageURL { | |
if url.absoluteString.components(separatedBy: "lkme.cc").count > 1 { | |
return LinkedME.getInstance().continue(userActivity); | |
} | |
} | |
return true | |
} | |
### swift3下的注册服务代码,(官方的demo,语法格式是旧的,能帮助到其他人最好,省时间!) | |
static func registeService(launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil){ | |
// Override point for customization after application launch. | |
let linkedme = LinkedME.getInstance(); | |
//是否开启Debug模式,开启Debug模式将会打印日志,上线时请关闭Debug模式 | |
linkedme?.setDebug(); | |
//解析深度链获取跳转参数,开发者自己实现参数相对应的页面内容。 | |
linkedme?.initSession(launchOptions: launchOptions, automaticallyDisplayDeepLinkController: false){ (params, error) in | |
if(error != nil){ | |
print(error ?? "call back with param error"); | |
}else{ | |
//[AnyHashable : Any]? | |
//print("LinkedME finished init with params\(params)") | |
guard let paramsDictionary = params as NSDictionary? else { | |
return | |
} | |
// $control 里面的参数是自己这边生成深度链接的自定义参数,可能在服务端,可能在web前端 | |
let controlObj = paramsDictionary["$control"] | |
if let controlDict = controlObj as? NSDictionary { | |
if let customerParam = controlDict["customerParam"] as? String { | |
print("LinkedME customerParam is \(customerParam)") | |
// 根据其它端传递过来的自定义参数跳转到对应的controller 即可 | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment