Created
November 1, 2016 09:37
-
-
Save danielvlopes/8494e498674211f4a6e6776cb8014b29 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
import UIKit | |
import SafariServices | |
let serviceName = "example" | |
// Redirect URI matching configuration in info.plist | |
// This is only required when linking to individual Applet Page instead of the Applets Index | |
let redirectURIQueryItem = NSURLQueryItem(name: "redirect_uri", value: "yourapp://auth.ifttt.com") | |
// Construct URL for applets index path | |
let appletIndexURL: NSURL = { | |
let components = NSURLComponents(string: "https://ifttt.com/\(serviceName)/embed") | |
return components!.URL! | |
}() | |
// Construct URL for an individual applets page | |
let appletPageURL: NSURL = { | |
let appletID = "_YOUR_APPLET_ID_" | |
let components = NSURLComponents(string: "https://ifttt.com/applets/\(appletID)/embed") | |
components?.queryItems = [redirectURIQueryItem] | |
return components!.URL! | |
}() | |
// Open URL with SFSafariViewController or in Safari app | |
if #available(iOS 9.0, *) { | |
let controller = SFSafariViewController(URL: appletIndexURL) | |
presentViewController(controller, animated: true, completion: nil) | |
} else { | |
UIApplication.sharedApplication().openURL(appletIndexURL) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment