Skip to content

Instantly share code, notes, and snippets.

@danielvlopes
Created November 1, 2016 09:38
Show Gist options
  • Save danielvlopes/2a56512063fdd6ae70c493ef87fe622c to your computer and use it in GitHub Desktop.
Save danielvlopes/2a56512063fdd6ae70c493ef87fe622c to your computer and use it in GitHub Desktop.
@import Foundation;
@import SafariServices;
NSString *serviceName = @"example";
// Redirect URI matching configuration in info.plist
// This is only required when linking to individual Applet Page instead of the Applets Index
NSURLQueryItem *redirectURIQueryItem = [NSURLQueryItem queryItemWithName:@"redirect_uri" value:@"yourapp://auth.ifttt.com"];
// Construct URL for applets index path
NSURLComponents *appletIndexComponents = [[NSURLComponents alloc] initWithString:[NSString stringWithFormat:@"https://ifttt.com/%@/embed", serviceName]];
NSURL *appletIndexURL = appletIndexComponents.URL;
// Construct URL for an individual applets page
NSString *appletId = @"_YOUR_APPLET_ID_";
NSURLComponents *appletPageComponents = [[NSURLComponents alloc] initWithString:[NSString stringWithFormat:@"https://ifttt.com/applets/%@/embed", appletId]];
appletPageComponents.queryItems = @[redirectURIQueryItem];
NSURL *appletPageURL = appletIndexComponents.URL;
// Open URL with SFSafariViewController or in Safari app
if ([SFSafariViewController class]) {
SFSafariViewController *sfViewController = [[SFSafariViewController alloc] initWithURL:appletIndexURL];
[self presentViewController:sfViewController animated:YES 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