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

modify requestPermissions method to open SFSafariViewController #124

Open
wants to merge 1 commit into
base: master
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
4 changes: 3 additions & 1 deletion venmo-sdk/Venmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ typedef void (^VENOAuthCompletionHandler)(BOOL success, NSError *error);
* @param permissions List of permissions.
* @param completionHandler Completion handler to call upon returning from OAuth flow.
*/
- (void)requestPermissions:(NSArray *)permissions withCompletionHandler:(VENOAuthCompletionHandler)handler;
- (void)requestPermissions:(NSArray *)permissions
fromViewController:(UIViewController *)viewController
withCompletionHandler:(VENOAuthCompletionHandler)handler;


/**
Expand Down
19 changes: 15 additions & 4 deletions venmo-sdk/Venmo.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#import "UIDevice+IdentifierAddition.h"
#endif

@import SafariServices;

static Venmo *sharedInstance = nil;

@interface VENSession ()
Expand All @@ -28,7 +30,7 @@ @interface VENSession ()

@end

@interface Venmo ()
@interface Venmo () <SFSafariViewControllerDelegate>

@property (copy, nonatomic, readwrite) NSString *appId;
@property (copy, nonatomic, readwrite) NSString *appSecret;
Expand Down Expand Up @@ -95,20 +97,29 @@ + (BOOL)isVenmoAppInstalled {
#pragma mark - Sessions

- (void)requestPermissions:(NSArray *)permissions
fromViewController:(UIViewController<SFSafariViewControllerDelegate> *)viewController
withCompletionHandler:(VENOAuthCompletionHandler)completionHandler {

NSString *scopeURLEncoded = [permissions componentsJoinedByString:@"%20"];
self.OAuthCompletionHandler = completionHandler;
self.session.state = VENSessionStateOpening;

NSString *baseURL;
if ([Venmo isVenmoAppInstalled]) {
baseURL = @"venmo://";
} else {
baseURL = [self baseURLPath];
}

NSURL *authURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@oauth/authorize?sdk=ios&client_id=%@&scope=%@&response_type=code", baseURL, self.appId, scopeURLEncoded]];

[[UIApplication sharedApplication] openURL:authURL];

if ([Venmo isVenmoAppInstalled]) {
[[UIApplication sharedApplication] openURL:authURL];
} else {
SFSafariViewController *safariViewController = [[SFSafariViewController alloc]initWithURL:authURL];
safariViewController.delegate = viewController;
[viewController presentViewController:safariViewController animated:YES completion:nil];
}
}


Expand Down