Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Use SFSafariViewController if available #109

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ SPEC CHECKSUMS:
SSKeychain: 3f42991739c6c60a9cf1bbd4dff6c0d3694bcf3d
VENCore: fb44651f466971a2f3585b7e4e5a13c1641da9bf

COCOAPODS: 0.37.2
COCOAPODS: 0.39.0
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
// :)
Expand Down
16 changes: 16 additions & 0 deletions sample/MiniVenmo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
B62D59CC189855E5001E46A4 /* Frameworks */,
B62D59CD189855E5001E46A4 /* Resources */,
A5FAE06903CE46D9BBD4689C /* Copy Pods Resources */,
3C06A013F5747EDCEE4EC428 /* Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions sample/MiniVenmo/MVMLoggedOutViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion sample/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '6.0'
platform :ios, '7.0'
inhibit_all_warnings!

target 'MiniVenmo', :exclusive => true do
Expand Down
26 changes: 13 additions & 13 deletions sample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
32 changes: 32 additions & 0 deletions venmo-sdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@
2D5EF54F17EF41B100DDD15A /* Frameworks */,
2D5EF55017EF41B100DDD15A /* Resources */,
7374F45841F24BED1351194B /* Copy Pods Resources */,
66C97EA230BFC90E1413ABF2 /* Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -454,6 +455,7 @@
EB49E22719266E0D008EA5DC /* Frameworks */,
EB49E22819266E0D008EA5DC /* Resources */,
2BF59B2DD4882A77B45CC6AD /* Copy Pods Resources */,
62F32408A695684869E46056 /* Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion venmo-sdk/Venmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 27 additions & 6 deletions venmo-sdk/Venmo.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "Venmo.h"

@import SafariServices;

#import "NSBundle+VenmoSDK.h"
#import "NSDictionary+VenmoSDK.h"
#import "NSError+VenmoSDK.h"
Expand Down Expand Up @@ -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];
}


Expand Down