Created
February 13, 2016 11:03
-
-
Save stoefln/b4820b11807fff7d099e to your computer and use it in GitHub Desktop.
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
// implementation based on http://blog.hokolinks.com/how-to-implement-apple-universal-links-on-ios-9/ | |
@available(iOS 8.0, *) | |
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool { | |
if userActivity.activityType == NSUserActivityTypeBrowsingWeb { | |
checkURL(userActivity.webpageURL!.absoluteString) | |
} | |
return true | |
} | |
func checkURL (entireURL: String) { | |
var imageURLs = [String]() | |
var logoURL : String = "" | |
var title : String = "" | |
var url : String = "" | |
//ASSUMPTION: "=" and "&" are not valid parts of urls and names | |
let query = NSURL(string: entireURL)!.query! | |
let arrQuery = query.componentsSeparatedByString("&") | |
for part in arrQuery { | |
var nameAndValue = part.componentsSeparatedByString("=") | |
if(nameAndValue[0] == "image_url" || nameAndValue[0] == "image_urls" ) { | |
imageURLs = nameAndValue[1].componentsSeparatedByString(",") | |
} else if(nameAndValue[0] == "logo_url") { | |
logoURL = nameAndValue[1]; | |
} else if(nameAndValue[0] == "title") { | |
title = nameAndValue[1].stringByRemovingPercentEncoding!; | |
} else if(nameAndValue[0] == "referer") { | |
url = nameAndValue[1].stringByRemovingPercentEncoding!; | |
} | |
} | |
let vc = self.window!.rootViewController as! MainViewController | |
if vc.isViewLoaded() { | |
vc.loadProduct(["logo_url":logoURL,"title":title,"image_urls":imageURLs,"url":url]) | |
} else { | |
startedWithProduct = ["logo_url":logoURL,"title":title,"image_urls":imageURLs,"url":url] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment