diff --git a/ios/Classes/TiWebdialogAuthenticationSessionProxy.h b/ios/Classes/TiWebdialogAuthenticationSessionProxy.h index f8d0075..42d514f 100644 --- a/ios/Classes/TiWebdialogAuthenticationSessionProxy.h +++ b/ios/Classes/TiWebdialogAuthenticationSessionProxy.h @@ -6,13 +6,16 @@ * Please see the LICENSE included with this distribution for details. */ -#if IS_IOS_11 - #import "TiProxy.h" -#import +#import -@interface TiWebdialogAuthenticationSessionProxy : TiProxy { - SFAuthenticationSession *_authSession; +#if IS_IOS_13 +@interface TiWebdialogAuthenticationSessionProxy : TiProxy +#else +@interface TiWebdialogAuthenticationSessionProxy : TiProxy +#endif +{ + id _authSession; } #pragma mark Public API's @@ -24,5 +27,3 @@ - (NSNumber *)isSupported:(id)unused; @end - -#endif diff --git a/ios/Classes/TiWebdialogAuthenticationSessionProxy.m b/ios/Classes/TiWebdialogAuthenticationSessionProxy.m index cf13813..5199015 100644 --- a/ios/Classes/TiWebdialogAuthenticationSessionProxy.m +++ b/ios/Classes/TiWebdialogAuthenticationSessionProxy.m @@ -6,46 +6,77 @@ * Please see the LICENSE included with this distribution for details. */ -#if IS_IOS_11 - #import "TiWebdialogAuthenticationSessionProxy.h" #import "TiUtils.h" +#import @implementation TiWebdialogAuthenticationSessionProxy -- (SFAuthenticationSession *)authSession +- (id)authSession { if (_authSession == nil) { NSString *url = [TiUtils stringValue:[self valueForKey:@"url"]]; NSString *scheme = [TiUtils stringValue:[self valueForKey:@"scheme"]]; - _authSession = [[SFAuthenticationSession alloc] initWithURL:[TiUtils toURL:url proxy:self] - callbackURLScheme:[TiUtils stringValue:scheme] - completionHandler:^(NSURL *callbackURL, NSError *error) { - NSMutableDictionary *event = [NSMutableDictionary dictionaryWithDictionary:@{ - @"success" : NUMBOOL(error == nil) + if ([TiUtils isIOSVersionOrGreater:@"12.0"]) { + _authSession = [[ASWebAuthenticationSession alloc] initWithURL:[TiUtils toURL:url proxy:self] + callbackURLScheme:scheme + completionHandler:^(NSURL *_Nullable callbackURL, NSError *_Nullable error) { + [self fireEventWithCallbackUrl:callbackURL andError:error]; + }]; +#if IS_IOS_13 + if ([TiUtils isIOSVersionOrGreater:@"13.0"]) { + ((ASWebAuthenticationSession *)_authSession).presentationContextProvider = self; + } +#endif + } else { + _authSession = [[SFAuthenticationSession alloc] initWithURL:[TiUtils toURL:url proxy:self] + callbackURLScheme:scheme + completionHandler:^(NSURL *callbackURL, NSError *error) { + [self fireEventWithCallbackUrl:callbackURL andError:error]; }]; + } + } - if (error != nil) { - [event setObject:[error localizedDescription] forKey:@"error"]; - } else { - [event setObject:[callbackURL absoluteString] forKey:@"callbackURL"]; - } + return _authSession; +} - if ([self _hasListeners:@"callback"]) { - [self fireEvent:@"callback" withObject:event]; - } - }]; +- (void)fireEventWithCallbackUrl:(NSURL *)callbackURL andError:(NSError *)error +{ + NSMutableDictionary *event = [NSMutableDictionary dictionaryWithDictionary:@{ + @"success" : NUMBOOL(error == nil) + }]; + + if (error != nil) { + [event setObject:[error localizedDescription] forKey:@"error"]; + } else { + [event setObject:[callbackURL absoluteString] forKey:@"callbackURL"]; } - return _authSession; + if ([self _hasListeners:@"callback"]) { + [self fireEvent:@"callback" withObject:event]; + } } +#pragma mark Delegate method + +#if IS_IOS_13 +- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session +{ + return [[UIApplication sharedApplication] keyWindow]; +} +#endif + #pragma mark Public API's - (void)start:(id)unused { - [[self authSession] start]; + id session = [self authSession]; + if ([session isKindOfClass:[SFAuthenticationSession class]]) { + [(SFAuthenticationSession *)session start]; + } else if ([session isKindOfClass:[ASWebAuthenticationSession class]]) { + [(ASWebAuthenticationSession *)session start]; + } } - (void)cancel:(id)unused @@ -59,5 +90,3 @@ - (NSNumber *)isSupported:(id)unused } @end - -#endif diff --git a/ios/Classes/TiWebdialogModule.m b/ios/Classes/TiWebdialogModule.m index 32ab897..617701f 100644 --- a/ios/Classes/TiWebdialogModule.m +++ b/ios/Classes/TiWebdialogModule.m @@ -63,7 +63,6 @@ - (SFSafariViewController *)safariController:(NSString *)url withEntersReaderIfA { if (_safariController == nil) { NSURL *safariURL = [NSURL URLWithString:[url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; -#if IS_IOS_11 if (@available(iOS 11.0, *)) { SFSafariViewControllerConfiguration *config = [[SFSafariViewControllerConfiguration alloc] init]; config.entersReaderIfAvailable = entersReaderIfAvailable; @@ -72,12 +71,9 @@ - (SFSafariViewController *)safariController:(NSString *)url withEntersReaderIfA _safariController = [[SFSafariViewController alloc] initWithURL:safariURL configuration:config]; } else { -#endif _safariController = [[SFSafariViewController alloc] initWithURL:safariURL entersReaderIfAvailable:entersReaderIfAvailable]; -#if IS_IOS_11 } -#endif [_safariController setDelegate:self]; } @@ -115,7 +111,7 @@ - (NSNumber *)isOpen:(id)unused - (NSNumber *)isSupported:(id)unused { - return NUMBOOL([TiUtils isIOS9OrGreater]); + return NUMBOOL([TiUtils isIOSVersionOrGreater:@"9.0"]); } - (void)close:(id)unused @@ -144,9 +140,7 @@ - (void)open:(id)args BOOL entersReaderIfAvailable = [TiUtils boolValue:@"entersReaderIfAvailable" properties:args def:YES]; BOOL barCollapsingEnabled = NO; -#if IS_IOS_11 barCollapsingEnabled = [TiUtils boolValue:@"barCollapsingEnabled" properties:args def:YES]; -#endif SFSafariViewController *safari = [self safariController:_url withEntersReaderIfAvailable:entersReaderIfAvailable andBarCollapsingEnabled:barCollapsingEnabled]; @@ -157,7 +151,7 @@ - (void)open:(id)args if ([args objectForKey:@"tintColor"]) { TiColor *newColor = [TiUtils colorValue:@"tintColor" properties:args]; - if ([TiUtils isIOS10OrGreater]) { + if ([TiUtils isIOSVersionOrGreater:@"10.0"]) { [safari setPreferredControlTintColor:[newColor _color]]; } else { [[safari view] setTintColor:[newColor _color]]; @@ -165,14 +159,13 @@ - (void)open:(id)args } if ([args objectForKey:@"barColor"]) { - if ([TiUtils isIOS10OrGreater]) { + if ([TiUtils isIOSVersionOrGreater:@"10.0"]) { [safari setPreferredBarTintColor:[[TiUtils colorValue:@"barColor" properties:args] _color]]; } else { NSLog(@"[ERROR] Ti.WebDialog: The barColor property is only available in iOS 10 and later"); } } -#if IS_IOS_11 if ([args objectForKey:@"dismissButtonStyle"]) { if (@available(iOS 11.0, *)) { [safari setDismissButtonStyle:[TiUtils intValue:@"dismissButtonStyle" properties:args def:SFSafariViewControllerDismissButtonStyleDone]]; @@ -180,7 +173,6 @@ - (void)open:(id)args NSLog(@"[ERROR] Ti.WebDialog: The dismissButtonStyle property is only available in iOS 11 and later"); } } -#endif [[TiApp app] showModalController:safari animated:animated]; @@ -198,10 +190,8 @@ - (void)open:(id)args #pragma mark Constants -#if IS_IOS_11 MAKE_SYSTEM_PROP(DISMISS_BUTTON_STYLE_DONE, SFSafariViewControllerDismissButtonStyleDone); MAKE_SYSTEM_PROP(DISMISS_BUTTON_STYLE_CLOSE, SFSafariViewControllerDismissButtonStyleClose); MAKE_SYSTEM_PROP(DISMISS_BUTTON_STYLE_CANCEL, SFSafariViewControllerDismissButtonStyleCancel); -#endif @end diff --git a/ios/TiWebdialog_Prefix.pch b/ios/TiWebdialog_Prefix.pch index ee43348..dc95fec 100644 --- a/ios/TiWebdialog_Prefix.pch +++ b/ios/TiWebdialog_Prefix.pch @@ -3,9 +3,8 @@ #import #endif -// iOS 11+ API's -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 -#define IS_IOS_11 true +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 +#define IS_IOS_13 true #else -#define IS_IOS_11 false +#define IS_IOS_13 false #endif diff --git a/ios/manifest b/ios/manifest index 5cd237c..731105c 100644 --- a/ios/manifest +++ b/ios/manifest @@ -2,7 +2,7 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 1.1.0 +version: 1.2.0 apiversion: 2 architectures: armv7 arm64 i386 x86_64 description: titanium-web-dialog diff --git a/ios/module.xcconfig b/ios/module.xcconfig index 62975c0..2b66972 100644 --- a/ios/module.xcconfig +++ b/ios/module.xcconfig @@ -1 +1 @@ -OTHER_LDFLAGS=$(inherited) -weak_framework SafariServices +OTHER_LDFLAGS=$(inherited) -weak_framework SafariServices -weak_framework AuthenticationServices diff --git a/ios/titanium.xcconfig b/ios/titanium.xcconfig index e19630d..4cc8a64 100644 --- a/ios/titanium.xcconfig +++ b/ios/titanium.xcconfig @@ -4,16 +4,13 @@ // OF YOUR TITANIUM SDK YOU'RE BUILDING FOR // // -TITANIUM_SDK_VERSION = 7.5.2.GA +TITANIUM_SDK_VERSION = 9.0.0.GA // // THESE SHOULD BE OK GENERALLY AS-IS // -TITANIUM_SDK = ~/Library/Application Support/Titanium/mobilesdk/osx/$(TITANIUM_SDK_VERSION) -TITANIUM_BASE_SDK = "$(TITANIUM_SDK)/iphone/include" -TITANIUM_BASE_SDK2 = "$(TITANIUM_SDK)/iphone/include/TiCore" -TITANIUM_BASE_SDK3 = "$(TITANIUM_SDK)/iphone/include/JavaScriptCore" -HEADER_SEARCH_PATHS= $(TITANIUM_BASE_SDK) $(TITANIUM_BASE_SDK2) $(TITANIUM_BASE_SDK3) +TITANIUM_SDK = /Users/$(USER)/Library/Application Support/Titanium/mobilesdk/osx/$(TITANIUM_SDK_VERSION) +HEADER_SEARCH_PATHS = $(inherited) "$(TITANIUM_SDK)/iphone/include" FRAMEWORK_SEARCH_PATHS = $(inherited) "$(TITANIUM_SDK)/iphone/Frameworks" diff --git a/package-lock.json b/package-lock.json index 329b884..e631aa2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@titanium-sdk/ti.webdialog", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6fdf52b..af67f07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanium-sdk/ti.webdialog", - "version": "2.0.0", + "version": "2.1.0", "description": "Use the native `SFSafariViewController` (iOS) and `Chrome Pages` (Android) within Axway Titanium.", "scripts": { "commit": "git-cz",