Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Add app extension compatibility #291

Merged
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
35 changes: 31 additions & 4 deletions BraintreeCore/BTAnalyticsMetadata.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,13 @@ - (NSString *)userInterfaceOrientation {
if ([UIApplication class] == nil) {
return nil;
}

UIInterfaceOrientation deviceOrientation = [[[[UIApplication sharedApplication] keyWindow] rootViewController] interfaceOrientation];

if ([self.class isAppExtension]) {
return nil;
}

UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
UIInterfaceOrientation deviceOrientation = [[[sharedApplication keyWindow] rootViewController] interfaceOrientation];

switch (deviceOrientation) {
case UIInterfaceOrientationPortrait:
Expand Down Expand Up @@ -219,24 +224,46 @@ - (NSString *)deviceScreenOrientation {
}

- (BOOL)isPaypalInstalled {
if ([self.class isAppExtension]) {
return false;
}

UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
static BOOL paypalInstalled;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURL *paypalV1URL = [NSURL URLWithString:@"com.paypal.ppclient.touch.v1://"];
NSURL *paypalV2URL = [NSURL URLWithString:@"com.paypal.ppclient.touch.v2://"];
paypalInstalled = [[UIApplication sharedApplication] canOpenURL:paypalV1URL] || [[UIApplication sharedApplication] canOpenURL:paypalV2URL];
paypalInstalled = [sharedApplication canOpenURL:paypalV1URL] || [sharedApplication canOpenURL:paypalV2URL];
});
return paypalInstalled;
}

- (BOOL)isVenmoInstalled {
if ([self.class isAppExtension]) {
return false;
}

UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
static BOOL venmoInstalled;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURL *venmoURL = [NSURL URLWithString:@"com.venmo.touch.v2://x-callback-url/vzero/auth"];
venmoInstalled = [[UIApplication sharedApplication] canOpenURL:venmoURL];
venmoInstalled = [sharedApplication canOpenURL:venmoURL];
});
return venmoInstalled;
}

+ (BOOL)isAppExtension {
static BOOL isExtension;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
NSDictionary *extensionDictionary = [[NSBundle mainBundle] infoDictionary][@"NSExtension"];
isExtension = [extensionDictionary isKindOfClass:[NSDictionary class]];
});

return isExtension;
}

@end