diff --git a/Podfile.lock b/Podfile.lock index b9f6218..12fc861 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -26,4 +26,4 @@ SPEC CHECKSUMS: SSKeychain: 3f42991739c6c60a9cf1bbd4dff6c0d3694bcf3d VENCore: fb44651f466971a2f3585b7e4e5a13c1641da9bf -COCOAPODS: 0.37.2 +COCOAPODS: 0.39.0 diff --git a/README.md b/README.md index 1986060..5fbce22 100644 --- a/README.md +++ b/README.md @@ -121,11 +121,12 @@ else { #### 5. Request permissions -You can request access to a user's Venmo account using `requestPermissions:withCompletionHandler:`. Permissions can be specified with [these scopes](https://developer.venmo.com/docs/authentication#scopes). If the user has the Venmo app installed, `requestPermissions:withCompletionHandler` will switch the user to an authorization page in the Venmo app. Otherwise, the user will be directed to an authorization page in Safari. After granting or denying permissions, the user will be redirected back to your app. +You can request access to a user's Venmo account using `requestPermissions:presentingViewController:withCompletionHandler:`. Permissions can be specified with [these scopes](https://developer.venmo.com/docs/authentication#scopes). If the user has the Venmo app installed, `requestPermissions:presentingViewController:withCompletionHandler` will switch the user to an authorization page in the Venmo app. Otherwise, the user will be directed to an authorization page in SFSafariViewController. After granting or denying permissions, the user will be redirected back to your app. ```obj-c [[Venmo sharedInstance] requestPermissions:@[VENPermissionMakePayments, VENPermissionAccessProfile] + presentingViewController:self // The view controller to present the SFSafariViewController withCompletionHandler:^(BOOL success, NSError *error) { if (success) { // :) diff --git a/sample/MiniVenmo.xcodeproj/project.pbxproj b/sample/MiniVenmo.xcodeproj/project.pbxproj index f3a093d..bf35be0 100644 --- a/sample/MiniVenmo.xcodeproj/project.pbxproj +++ b/sample/MiniVenmo.xcodeproj/project.pbxproj @@ -187,6 +187,7 @@ B62D59CC189855E5001E46A4 /* Frameworks */, B62D59CD189855E5001E46A4 /* Resources */, A5FAE06903CE46D9BBD4689C /* Copy Pods Resources */, + 3C06A013F5747EDCEE4EC428 /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -286,6 +287,21 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; + 3C06A013F5747EDCEE4EC428 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-MiniVenmo/Pods-MiniVenmo-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; A5FAE06903CE46D9BBD4689C /* Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/sample/MiniVenmo/MVMLoggedOutViewController.m b/sample/MiniVenmo/MVMLoggedOutViewController.m index 0c6f293..43bc756 100644 --- a/sample/MiniVenmo/MVMLoggedOutViewController.m +++ b/sample/MiniVenmo/MVMLoggedOutViewController.m @@ -31,6 +31,7 @@ - (void)presentLoggedInVC { - (IBAction)logInButtonAction:(id)sender { [[Venmo sharedInstance] requestPermissions:@[VENPermissionMakePayments, VENPermissionAccessProfile] + presentingViewController:self withCompletionHandler:^(BOOL success, NSError *error) { if (success) { [self presentLoggedInVC]; diff --git a/sample/Podfile b/sample/Podfile index 92f07f4..4890fd9 100644 --- a/sample/Podfile +++ b/sample/Podfile @@ -1,4 +1,4 @@ -platform :ios, '6.0' +platform :ios, '7.0' inhibit_all_warnings! target 'MiniVenmo', :exclusive => true do diff --git a/sample/Podfile.lock b/sample/Podfile.lock index 1839d1d..c038732 100644 --- a/sample/Podfile.lock +++ b/sample/Podfile.lock @@ -21,15 +21,15 @@ PODS: - AFNetworking/NSURLConnection - AFNetworking/NSURLSession - CMDQueryStringSerialization (0.2.0) - - SSKeychain (1.2.2) + - SSKeychain (1.2.3) - SVProgressHUD (1.0) - UIAlertView+Blocks (0.8.1) - - VENCore (3.0.1): + - VENCore (3.1.1): - CMDQueryStringSerialization (~> 0.2.0) - Venmo-iOS-SDK (1.3.0): - CMDQueryStringSerialization (~> 0.2.0) - - SSKeychain (~> 1.2.2) - - VENCore (~> 3.0.0) + - SSKeychain (~> 1.2.3) + - VENCore (~> 3.1.1) DEPENDENCIES: - AFNetworking (~> 2.3) @@ -39,15 +39,15 @@ DEPENDENCIES: EXTERNAL SOURCES: Venmo-iOS-SDK: - :path: .. + :path: ".." SPEC CHECKSUMS: - AFNetworking: 6d7b76aa5d04c8c37daad3eef4b7e3f2a7620da3 - CMDQueryStringSerialization: e53570ccbce6004acba30b1c1210e254644cdb92 - SSKeychain: cc48bd3ad24fcd9125adb9e0d23dd50b8bbd08b9 - SVProgressHUD: 5034c6e22b8c2ca3e09402e48d41ed0340aa1c50 - UIAlertView+Blocks: 0b749f1f7bd5131ff2233b30a406c1585a7171b2 - VENCore: 944d7fc21a27670cf57342b35ce3d715ce514ca5 - Venmo-iOS-SDK: 5c5aab6f3dc448bf2ee0c0fbb706a190bcccc115 + AFNetworking: 05b9f6e3aa5ac45bc383b4bb108ef338080a26c7 + CMDQueryStringSerialization: 15f9004212bbc72533bb533f63df79d90a00a7d8 + SSKeychain: 3f42991739c6c60a9cf1bbd4dff6c0d3694bcf3d + SVProgressHUD: 46088807596a795cbcb4affd92cf3f13b6ab3dda + UIAlertView+Blocks: 45c3d3b7194906702d3e9a14c7ece5581505646d + VENCore: fb44651f466971a2f3585b7e4e5a13c1641da9bf + Venmo-iOS-SDK: 19b0cbdef45450ab433c9250a9097fb7ddd1f24d -COCOAPODS: 0.35.0 +COCOAPODS: 0.39.0 diff --git a/venmo-sdk.xcodeproj/project.pbxproj b/venmo-sdk.xcodeproj/project.pbxproj index 60097ff..69e5a5e 100644 --- a/venmo-sdk.xcodeproj/project.pbxproj +++ b/venmo-sdk.xcodeproj/project.pbxproj @@ -434,6 +434,7 @@ 2D5EF54F17EF41B100DDD15A /* Frameworks */, 2D5EF55017EF41B100DDD15A /* Resources */, 7374F45841F24BED1351194B /* Copy Pods Resources */, + 66C97EA230BFC90E1413ABF2 /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -454,6 +455,7 @@ EB49E22719266E0D008EA5DC /* Frameworks */, EB49E22819266E0D008EA5DC /* Resources */, 2BF59B2DD4882A77B45CC6AD /* Copy Pods Resources */, + 62F32408A695684869E46056 /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -562,6 +564,36 @@ shellPath = /bin/sh; shellScript = "set -e\n\nmkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/Versions/A/Headers\"\n\n# Link the \"Current\" version to \"A\"\n/bin/ln -sfh A \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/Versions/Current\"\n/bin/ln -sfh Versions/Current/Headers \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/Headers\"\n/bin/ln -sfh \"Versions/Current/${PRODUCT_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/${PRODUCT_NAME}\"\n\n# The -a ensures that the headers maintain the source modification date so that we don't constantly\n# cause propagating rebuilds of files that import these headers.\n/bin/cp -a \"${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/Versions/A/Headers\"\n"; }; + 62F32408A695684869E46056 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-venmo-sdk-integration-specs/Pods-venmo-sdk-integration-specs-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 66C97EA230BFC90E1413ABF2 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-venmo-sdk-specs/Pods-venmo-sdk-specs-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; 7374F45841F24BED1351194B /* Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/venmo-sdk/Venmo.h b/venmo-sdk/Venmo.h index d155cbb..338ff5e 100644 --- a/venmo-sdk/Venmo.h +++ b/venmo-sdk/Venmo.h @@ -70,10 +70,15 @@ typedef void (^VENOAuthCompletionHandler)(BOOL success, NSError *error); /** * Initiates Venmo OAuth request. * @param permissions List of permissions. + * @param presentingViewController The view controller that present the SFSafariViewController if the Venmo app is not installed * @param completionHandler Completion handler to call upon returning from OAuth flow. */ -- (void)requestPermissions:(NSArray *)permissions withCompletionHandler:(VENOAuthCompletionHandler)handler; +- (void)requestPermissions:(NSArray *)permissions + presentingViewController:(UIViewController *)presentingViewController + withCompletionHandler:(VENOAuthCompletionHandler)completionHandler; +- (void)requestPermissions:(NSArray *)permissions + withCompletionHandler:(VENOAuthCompletionHandler)completionHandler __attribute__((deprecated)); /** * Returns a value indicating whether the access token should be refreshed. diff --git a/venmo-sdk/Venmo.m b/venmo-sdk/Venmo.m index 05290a2..55d57fb 100644 --- a/venmo-sdk/Venmo.m +++ b/venmo-sdk/Venmo.m @@ -1,5 +1,7 @@ #import "Venmo.h" +@import SafariServices; + #import "NSBundle+VenmoSDK.h" #import "NSDictionary+VenmoSDK.h" #import "NSError+VenmoSDK.h" @@ -95,20 +97,39 @@ + (BOOL)isVenmoAppInstalled { #pragma mark - Sessions - (void)requestPermissions:(NSArray *)permissions + presentingViewController:(__weak UIViewController *)presentingViewController withCompletionHandler:(VENOAuthCompletionHandler)completionHandler { NSString *scopeURLEncoded = [permissions componentsJoinedByString:@"%20"]; - self.OAuthCompletionHandler = completionHandler; + + VENOAuthCompletionHandler handler = ^(BOOL success, NSError *error) { + [presentingViewController dismissViewControllerAnimated:YES completion:nil]; + if (completionHandler) { + completionHandler(success, error); + } + }; + + self.OAuthCompletionHandler = handler; self.session.state = VENSessionStateOpening; - NSString *baseURL; + NSString *authURLString = [NSString stringWithFormat:@"oauth/authorize?sdk=ios&client_id=%@&scope=%@&response_type=code", self.appId, scopeURLEncoded]; + if ([Venmo isVenmoAppInstalled]) { - baseURL = @"venmo://"; + NSURL *url = [[NSURL alloc] initWithString:[@"venmo://" stringByAppendingString:authURLString]]; + [[UIApplication sharedApplication] openURL:url]; } else { - baseURL = [self baseURLPath]; + NSURL *url = [[NSURL alloc] initWithString:[[self baseURLPath] stringByAppendingString:authURLString]]; + if(presentingViewController && NSClassFromString(@"SFSafariViewController")) { + SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url]; + [presentingViewController presentViewController:safariViewController animated:YES completion:nil]; + } else { + [[UIApplication sharedApplication] openURL:url]; + } } - NSURL *authURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@oauth/authorize?sdk=ios&client_id=%@&scope=%@&response_type=code", baseURL, self.appId, scopeURLEncoded]]; +} - [[UIApplication sharedApplication] openURL:authURL]; +- (void)requestPermissions:(NSArray *)permissions + withCompletionHandler:(VENOAuthCompletionHandler)completionHandler { + [self requestPermissions:permissions presentingViewController:nil withCompletionHandler:completionHandler]; }