This is an automated email from the ASF dual-hosted git repository.
manuelbeck pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/cordova-plugin-inappbrowser.git
The following commit(s) were added to refs/heads/master by this push:
new fb5b469 feat(ios): correct code formatting (#1100)
fb5b469 is described below
commit fb5b46974309027775f6b1b361600eca75e82050
Author: Manuel Beck <[email protected]>
AuthorDate: Fri Jan 30 17:54:44 2026 +0100
feat(ios): correct code formatting (#1100)
- Proper method declarations alignment: Use linux brace style, correct
whitespaces, no whitespace between type and pointer
- Add missing whitespaces for if conditions: Sometimes no whitespace was
set between `if` and `(` or between `)` and `{`
- Remove some unneccessary empty lines between code
- Correct missing parameter labels for `showToolBar:` and
`setCloseButtonTitle:` in `CDVWKInAppBrowser`
- Format protocols of `CDVWKInAppBrowserViewController`on mutliple lines
- Partially Generated-By: GPT-5.2-Codex
---
src/ios/CDVInAppBrowserNavigationController.m | 11 +-
src/ios/CDVInAppBrowserOptions.h | 18 +-
src/ios/CDVInAppBrowserOptions.m | 18 +-
src/ios/CDVWKInAppBrowser.h | 61 +++---
src/ios/CDVWKInAppBrowser.m | 295 +++++++++++++-------------
src/ios/CDVWKInAppBrowserUIDelegate.h | 8 +-
src/ios/CDVWKInAppBrowserUIDelegate.m | 50 ++---
7 files changed, 235 insertions(+), 226 deletions(-)
diff --git a/src/ios/CDVInAppBrowserNavigationController.m
b/src/ios/CDVInAppBrowserNavigationController.m
index 8b93fb8..2828de3 100644
--- a/src/ios/CDVInAppBrowserNavigationController.m
+++ b/src/ios/CDVInAppBrowserNavigationController.m
@@ -21,17 +21,20 @@
@implementation CDVInAppBrowserNavigationController : UINavigationController
-- (void) dismissViewControllerAnimated:(BOOL)flag completion:(void
(^)(void))completion {
- if ( self.presentedViewController) {
+- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void
(^)(void))completion
+{
+ if (self.presentedViewController) {
[super dismissViewControllerAnimated:flag completion:completion];
}
}
-- (void) viewDidLoad {
+- (void)viewDidLoad
+{
[super viewDidLoad];
}
-- (CGRect) invertFrameIfNeeded:(CGRect)rect {
+- (CGRect)invertFrameIfNeeded:(CGRect)rect
+{
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]
statusBarOrientation])) {
CGFloat temp = rect.size.width;
rect.size.width = rect.size.height;
diff --git a/src/ios/CDVInAppBrowserOptions.h b/src/ios/CDVInAppBrowserOptions.h
index d66ce94..83df264 100644
--- a/src/ios/CDVInAppBrowserOptions.h
+++ b/src/ios/CDVInAppBrowserOptions.h
@@ -23,29 +23,29 @@
@property (nonatomic, assign) BOOL location;
@property (nonatomic, assign) BOOL toolbar;
-@property (nonatomic, copy) NSString* closebuttoncaption;
-@property (nonatomic, copy) NSString* closebuttoncolor;
+@property (nonatomic, copy) NSString *closebuttoncaption;
+@property (nonatomic, copy) NSString *closebuttoncolor;
@property (nonatomic, assign) BOOL lefttoright;
-@property (nonatomic, copy) NSString* toolbarposition;
-@property (nonatomic, copy) NSString* toolbarcolor;
+@property (nonatomic, copy) NSString *toolbarposition;
+@property (nonatomic, copy) NSString *toolbarcolor;
@property (nonatomic, assign) BOOL toolbartranslucent;
@property (nonatomic, assign) BOOL hidenavigationbuttons;
-@property (nonatomic, copy) NSString* navigationbuttoncolor;
+@property (nonatomic, copy) NSString *navigationbuttoncolor;
@property (nonatomic, assign) BOOL cleardata;
@property (nonatomic, assign) BOOL clearcache;
@property (nonatomic, assign) BOOL clearsessioncache;
@property (nonatomic, assign) BOOL hidespinner;
-@property (nonatomic, copy) NSString* presentationstyle;
-@property (nonatomic, copy) NSString* transitionstyle;
+@property (nonatomic, copy) NSString *presentationstyle;
+@property (nonatomic, copy) NSString *transitionstyle;
@property (nonatomic, assign) BOOL enableviewportscale;
@property (nonatomic, assign) BOOL mediaplaybackrequiresuseraction;
@property (nonatomic, assign) BOOL allowinlinemediaplayback;
@property (nonatomic, assign) BOOL hidden;
@property (nonatomic, assign) BOOL disallowoverscroll;
-@property (nonatomic, copy) NSString* beforeload;
+@property (nonatomic, copy) NSString *beforeload;
-+ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options;
++ (CDVInAppBrowserOptions *)parseOptions:(NSString *)options;
@end
diff --git a/src/ios/CDVInAppBrowserOptions.m b/src/ios/CDVInAppBrowserOptions.m
index 67a8aee..cc77788 100644
--- a/src/ios/CDVInAppBrowserOptions.m
+++ b/src/ios/CDVInAppBrowserOptions.m
@@ -50,24 +50,24 @@
return self;
}
-+ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options
++ (CDVInAppBrowserOptions *)parseOptions:(NSString *)options
{
- CDVInAppBrowserOptions* obj = [[CDVInAppBrowserOptions alloc] init];
+ CDVInAppBrowserOptions *obj = [[CDVInAppBrowserOptions alloc] init];
// NOTE: this parsing does not handle quotes within values
- NSArray* pairs = [options componentsSeparatedByString:@","];
+ NSArray *pairs = [options componentsSeparatedByString:@","];
// parse keys and values, set the properties
- for (NSString* pair in pairs) {
- NSArray* keyvalue = [pair componentsSeparatedByString:@"="];
+ for (NSString *pair in pairs) {
+ NSArray *keyvalue = [pair componentsSeparatedByString:@"="];
if ([keyvalue count] == 2) {
- NSString* key = [[keyvalue objectAtIndex:0] lowercaseString];
- NSString* value = [keyvalue objectAtIndex:1];
- NSString* value_lc = [value lowercaseString];
+ NSString *key = [[keyvalue objectAtIndex:0] lowercaseString];
+ NSString *value = [keyvalue objectAtIndex:1];
+ NSString *value_lc = [value lowercaseString];
BOOL isBoolean = [value_lc isEqualToString:@"yes"] || [value_lc
isEqualToString:@"no"];
- NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc]
init];
+ NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc]
init];
[numberFormatter setAllowsFloats:YES];
BOOL isNumber = [numberFormatter numberFromString:value_lc] != nil;
diff --git a/src/ios/CDVWKInAppBrowser.h b/src/ios/CDVWKInAppBrowser.h
index e9e89d8..cbf196a 100644
--- a/src/ios/CDVWKInAppBrowser.h
+++ b/src/ios/CDVWKInAppBrowser.h
@@ -26,55 +26,60 @@
@class CDVWKInAppBrowserViewController;
-@interface CDVWKInAppBrowser : CDVPlugin {
+@interface CDVWKInAppBrowser : CDVPlugin
+{
UIWindow * tmpWindow;
@private
- NSString* _beforeload;
+ NSString *_beforeload;
BOOL _waitForBeforeload;
}
-@property (nonatomic, retain) CDVWKInAppBrowser* instance;
-@property (nonatomic, retain) CDVWKInAppBrowserViewController*
inAppBrowserViewController;
-@property (nonatomic, copy) NSString* callbackId;
+@property (nonatomic, retain) CDVWKInAppBrowser *instance;
+@property (nonatomic, retain) CDVWKInAppBrowserViewController
*inAppBrowserViewController;
+@property (nonatomic, copy) NSString *callbackId;
@property (nonatomic, copy) NSRegularExpression *callbackIdPattern;
+ (id) getInstance;
-- (void)open:(CDVInvokedUrlCommand*)command;
-- (void)close:(CDVInvokedUrlCommand*)command;
-- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
-- (void)show:(CDVInvokedUrlCommand*)command;
-- (void)hide:(CDVInvokedUrlCommand*)command;
-- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command;
+- (void)open:(CDVInvokedUrlCommand *)command;
+- (void)close:(CDVInvokedUrlCommand *)command;
+- (void)injectScriptCode:(CDVInvokedUrlCommand *)command;
+- (void)show:(CDVInvokedUrlCommand *)command;
+- (void)hide:(CDVInvokedUrlCommand *)command;
+- (void)loadAfterBeforeload:(CDVInvokedUrlCommand *)command;
@end
-@interface CDVWKInAppBrowserViewController : UIViewController
<CDVScreenOrientationDelegate,WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,UIAdaptivePresentationControllerDelegate>{
+@interface CDVWKInAppBrowserViewController : UIViewController
<CDVScreenOrientationDelegate,
+
WKNavigationDelegate,
+ WKUIDelegate,
+
WKScriptMessageHandler,
+
UIAdaptivePresentationControllerDelegate>
+{
@private
CDVInAppBrowserOptions *_browserOptions;
NSDictionary *_settings;
}
-@property (nonatomic, strong) IBOutlet WKWebView* webView;
-@property (nonatomic, strong) IBOutlet WKWebViewConfiguration* configuration;
-@property (nonatomic, strong) IBOutlet UIBarButtonItem* closeButton;
-@property (nonatomic, strong) IBOutlet UILabel* addressLabel;
-@property (nonatomic, strong) IBOutlet UIBarButtonItem* backButton;
-@property (nonatomic, strong) IBOutlet UIBarButtonItem* forwardButton;
-@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
-@property (nonatomic, strong) IBOutlet UIToolbar* toolbar;
-@property (nonatomic, strong) IBOutlet CDVWKInAppBrowserUIDelegate*
webViewUIDelegate;
+@property (nonatomic, strong) IBOutlet WKWebView *webView;
+@property (nonatomic, strong) IBOutlet WKWebViewConfiguration *configuration;
+@property (nonatomic, strong) IBOutlet UIBarButtonItem *closeButton;
+@property (nonatomic, strong) IBOutlet UILabel *addressLabel;
+@property (nonatomic, strong) IBOutlet UIBarButtonItem *backButton;
+@property (nonatomic, strong) IBOutlet UIBarButtonItem *forwardButton;
+@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *spinner;
+@property (nonatomic, strong) IBOutlet UIToolbar *toolbar;
+@property (nonatomic, strong) IBOutlet CDVWKInAppBrowserUIDelegate
*webViewUIDelegate;
@property (nonatomic, weak) id <CDVScreenOrientationDelegate>
orientationDelegate;
-@property (nonatomic, weak) CDVWKInAppBrowser* navigationDelegate;
-@property (nonatomic) NSURL* currentURL;
+@property (nonatomic, weak) CDVWKInAppBrowser *navigationDelegate;
+@property (nonatomic) NSURL *currentURL;
- (void)close;
-- (void)navigateTo:(NSURL*)url;
+- (void)navigateTo:(NSURL *)url;
- (void)showLocationBar:(BOOL)show;
-- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
-- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int)
buttonIndex;
-
-- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions
andSettings:(NSDictionary*) settings;
+- (void)showToolBar:(BOOL)show atPosition:(NSString *)toolbarPosition;
+- (void)setCloseButtonTitle:(NSString *)title withColor:(NSString
*)colorString atIndex:(int)buttonIndex;
+- (id)initWithBrowserOptions:(CDVInAppBrowserOptions *)browserOptions
andSettings:(NSDictionary *)settings;
@end
diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m
index 26e44bb..cfd5725 100644
--- a/src/ios/CDVWKInAppBrowser.m
+++ b/src/ios/CDVWKInAppBrowser.m
@@ -35,9 +35,10 @@
@implementation CDVWKInAppBrowser
-static CDVWKInAppBrowser* instance = nil;
+static CDVWKInAppBrowser *instance = nil;
-+ (id) getInstance{
++ (id)getInstance
+{
return instance;
}
@@ -54,7 +55,7 @@ static CDVWKInAppBrowser* instance = nil;
[self close:nil];
}
-- (void)close:(CDVInvokedUrlCommand*)command
+- (void)close:(CDVInvokedUrlCommand *)command
{
if (self.inAppBrowserViewController == nil) {
NSLog(@"IAB.close() called but it was already closed.");
@@ -65,7 +66,7 @@ static CDVWKInAppBrowser* instance = nil;
[self.inAppBrowserViewController close];
}
-- (BOOL) isSystemUrl:(NSURL*)url
+- (BOOL)isSystemUrl:(NSURL *)url
{
if ([[url host] isEqualToString:@"itunes.apple.com"]) {
return YES;
@@ -74,19 +75,19 @@ static CDVWKInAppBrowser* instance = nil;
return NO;
}
-- (void)open:(CDVInvokedUrlCommand*)command
+- (void)open:(CDVInvokedUrlCommand *)command
{
- CDVPluginResult* pluginResult;
+ CDVPluginResult *pluginResult;
- NSString* url = [command argumentAtIndex:0];
- NSString* target = [command argumentAtIndex:1
withDefault:kInAppBrowserTargetSelf];
- NSString* options = [command argumentAtIndex:2 withDefault:@""
andClass:[NSString class]];
+ NSString *url = [command argumentAtIndex:0];
+ NSString *target = [command argumentAtIndex:1
withDefault:kInAppBrowserTargetSelf];
+ NSString *options = [command argumentAtIndex:2 withDefault:@""
andClass:[NSString class]];
self.callbackId = command.callbackId;
if (url != nil) {
- NSURL* baseUrl = [self.webViewEngine URL];
- NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl]
absoluteURL];
+ NSURL *baseUrl = [self.webViewEngine URL];
+ NSURL *absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl]
absoluteURL];
if ([self isSystemUrl:absoluteUrl]) {
target = kInAppBrowserTargetSystem;
@@ -109,14 +110,13 @@ static CDVWKInAppBrowser* instance = nil;
[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}
-- (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
+- (void)openInInAppBrowser:(NSURL *)url withOptions:(NSString *)options
{
- CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions
parseOptions:options];
-
- WKWebsiteDataStore* dataStore = [WKWebsiteDataStore defaultDataStore];
+ CDVInAppBrowserOptions *browserOptions = [CDVInAppBrowserOptions
parseOptions:options];
+ WKWebsiteDataStore *dataStore = [WKWebsiteDataStore defaultDataStore];
+
if (browserOptions.cleardata) {
-
- NSDate* dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
+ NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes]
modifiedSince:dateFrom completionHandler:^{
NSLog(@"Removed all WKWebView data");
self.inAppBrowserViewController.webView.configuration.processPool
= [[WKProcessPool alloc] init]; // create new process pool to flush all data
@@ -125,10 +125,10 @@ static CDVWKInAppBrowser* instance = nil;
if (browserOptions.clearcache) {
// Deletes all cookies
- WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
- [cookieStore getAllCookies:^(NSArray* cookies) {
- NSHTTPCookie* cookie;
- for(cookie in cookies){
+ WKHTTPCookieStore *cookieStore = dataStore.httpCookieStore;
+ [cookieStore getAllCookies:^(NSArray *cookies) {
+ NSHTTPCookie *cookie;
+ for (cookie in cookies) {
[cookieStore deleteCookie:cookie completionHandler:nil];
}
}];
@@ -136,11 +136,11 @@ static CDVWKInAppBrowser* instance = nil;
if (browserOptions.clearsessioncache) {
// Deletes session cookies
- WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
- [cookieStore getAllCookies:^(NSArray* cookies) {
- NSHTTPCookie* cookie;
- for(cookie in cookies){
- if(cookie.sessionOnly){
+ WKHTTPCookieStore *cookieStore = dataStore.httpCookieStore;
+ [cookieStore getAllCookies:^(NSArray *cookies) {
+ NSHTTPCookie *cookie;
+ for (cookie in cookies) {
+ if (cookie.sessionOnly) {
[cookieStore deleteCookie:cookie completionHandler:nil];
}
}
@@ -152,15 +152,15 @@ static CDVWKInAppBrowser* instance = nil;
self.inAppBrowserViewController.navigationDelegate = self;
if ([self.viewController
conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {
- self.inAppBrowserViewController.orientationDelegate =
(UIViewController <CDVScreenOrientationDelegate>*)self.viewController;
+ self.inAppBrowserViewController.orientationDelegate =
(UIViewController <CDVScreenOrientationDelegate> *)self.viewController;
}
}
[self.inAppBrowserViewController showLocationBar:browserOptions.location];
- [self.inAppBrowserViewController showToolBar:browserOptions.toolbar
:browserOptions.toolbarposition];
+ [self.inAppBrowserViewController showToolBar:browserOptions.toolbar
atPosition:browserOptions.toolbarposition];
if (browserOptions.closebuttoncaption != nil ||
browserOptions.closebuttoncolor != nil) {
int closeButtonIndex = browserOptions.lefttoright ?
(browserOptions.hidenavigationbuttons ? 1 : 4) : 0;
- [self.inAppBrowserViewController
setCloseButtonTitle:browserOptions.closebuttoncaption
:browserOptions.closebuttoncolor :closeButtonIndex];
+ [self.inAppBrowserViewController
setCloseButtonTitle:browserOptions.closebuttoncaption
withColor:browserOptions.closebuttoncolor atIndex:closeButtonIndex];
}
// Set Presentation Style
UIModalPresentationStyle presentationStyle =
UIModalPresentationFullScreen; // default
@@ -187,20 +187,20 @@ static CDVWKInAppBrowser* instance = nil;
//prevent webView from bouncing
if (browserOptions.disallowoverscroll) {
if ([self.inAppBrowserViewController.webView
respondsToSelector:@selector(scrollView)]) {
- ((UIScrollView*)[self.inAppBrowserViewController.webView
scrollView]).bounces = NO;
+ ((UIScrollView *)[self.inAppBrowserViewController.webView
scrollView]).bounces = NO;
} else {
for (id subview in
self.inAppBrowserViewController.webView.subviews) {
if ([[subview class] isSubclassOfClass:[UIScrollView class]]) {
- ((UIScrollView*)subview).bounces = NO;
+ ((UIScrollView *)subview).bounces = NO;
}
}
}
}
// use of beforeload event
- if([browserOptions.beforeload isKindOfClass:[NSString class]]){
+ if ([browserOptions.beforeload isKindOfClass:[NSString class]]) {
_beforeload = browserOptions.beforeload;
- }else{
+ } else {
_beforeload = @"yes";
}
_waitForBeforeload = ![_beforeload isEqualToString:@""];
@@ -211,14 +211,15 @@ static CDVWKInAppBrowser* instance = nil;
}
}
-- (void)show:(CDVInvokedUrlCommand*)command{
+- (void)show:(CDVInvokedUrlCommand *)command
+{
[self show:command withNoAnimate:NO];
}
-- (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
+- (void)show:(CDVInvokedUrlCommand *)command withNoAnimate:(BOOL)noAnimate
{
BOOL initHidden = NO;
- if(command == nil && noAnimate == YES){
+ if (command == nil && noAnimate == YES) {
initHidden = YES;
}
@@ -227,14 +228,14 @@ static CDVWKInAppBrowser* instance = nil;
return;
}
- __block CDVInAppBrowserNavigationController* nav =
[[CDVInAppBrowserNavigationController alloc]
+ __block CDVInAppBrowserNavigationController *nav =
[[CDVInAppBrowserNavigationController alloc]
initWithRootViewController:self.inAppBrowserViewController];
nav.orientationDelegate = self.inAppBrowserViewController;
nav.navigationBarHidden = YES;
nav.modalPresentationStyle =
self.inAppBrowserViewController.modalPresentationStyle;
nav.presentationController.delegate = self.inAppBrowserViewController;
- __weak CDVWKInAppBrowser* weakSelf = self;
+ __weak CDVWKInAppBrowser *weakSelf = self;
// Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{
@@ -251,7 +252,7 @@ static CDVWKInAppBrowser* instance = nil;
if (!strongSelf->tmpWindow) {
CGRect frame = [[UIScreen mainScreen] bounds];
- if(initHidden && osVersion < 11){
+ if (initHidden && osVersion < 11) {
frame.origin.x = -10000;
}
strongSelf->tmpWindow = [[UIWindow alloc]
initWithFrame:frame];
@@ -261,7 +262,7 @@ static CDVWKInAppBrowser* instance = nil;
[strongSelf->tmpWindow setRootViewController:tmpController];
[strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal];
- if(!initHidden || osVersion < 11){
+ if (!initHidden || osVersion < 11) {
[self->tmpWindow makeKeyAndVisible];
}
[tmpController presentViewController:nav animated:!noAnimate
completion:nil];
@@ -269,7 +270,7 @@ static CDVWKInAppBrowser* instance = nil;
});
}
-- (void)hide:(CDVInvokedUrlCommand*)command
+- (void)hide:(CDVInvokedUrlCommand *)command
{
// Set tmpWindow to hidden to make main webview responsive to touch again
// https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
@@ -291,15 +292,15 @@ static CDVWKInAppBrowser* instance = nil;
});
}
-- (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
+- (void)openInCordovaWebView:(NSURL *)url withOptions:(NSString *)options
{
- NSURLRequest* request = [NSURLRequest requestWithURL:url];
+ NSURLRequest *request = [NSURLRequest requestWithURL:url];
// the webview engine itself will filter for this according to
<allow-navigation> policy
// in config.xml
[self.webViewEngine loadRequest:request];
}
-- (void)openInSystem:(NSURL*)url
+- (void)openInSystem:(NSURL *)url
{
[[UIApplication sharedApplication] openURL:url options:@{}
completionHandler:^(BOOL success) {
if (!success) {
@@ -308,9 +309,9 @@ static CDVWKInAppBrowser* instance = nil;
}];
}
-- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
+- (void)loadAfterBeforeload:(CDVInvokedUrlCommand *)command
{
- NSString* urlStr = [command argumentAtIndex:0];
+ NSString *urlStr = [command argumentAtIndex:0];
if ([_beforeload isEqualToString:@""]) {
NSLog(@"unexpected loadAfterBeforeload called without feature
beforeload=get|post");
@@ -324,7 +325,7 @@ static CDVWKInAppBrowser* instance = nil;
return;
}
- NSURL* url = [NSURL URLWithString:urlStr];
+ NSURL *url = [NSURL URLWithString:urlStr];
//_beforeload = @"";
_waitForBeforeload = NO;
[self.inAppBrowserViewController navigateTo:url];
@@ -339,17 +340,17 @@ static CDVWKInAppBrowser* instance = nil;
//
// If no wrapper is supplied, then the source string is executed directly.
-- (void)injectDeferredObject:(NSString*)source withWrapper:(NSString*)jsWrapper
+- (void)injectDeferredObject:(NSString *)source withWrapper:(NSString
*)jsWrapper
{
// Ensure a message handler bridge is created to communicate with the
CDVWKInAppBrowserViewController
- [self evaluateJavaScript: [NSString
stringWithFormat:@"(function(w){if(!w._cdvMessageHandler) {w._cdvMessageHandler
= function(id,d){w.webkit.messageHandlers.%@.postMessage({d:d,
id:id});}}})(window)", IAB_BRIDGE_NAME]];
+ [self evaluateJavaScript: [NSString stringWithFormat:@"(function(w){if
(!w._cdvMessageHandler) {w._cdvMessageHandler =
function(id,d){w.webkit.messageHandlers.%@.postMessage({d:d,
id:id});}}})(window)", IAB_BRIDGE_NAME]];
if (jsWrapper != nil) {
- NSData* jsonData = [NSJSONSerialization dataWithJSONObject:@[source]
options:0 error:nil];
- NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@[source]
options:0 error:nil];
+ NSString *sourceArrayString = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
if (sourceArrayString) {
- NSString* sourceString = [sourceArrayString
substringWithRange:NSMakeRange(1, [sourceArrayString length] - 2)];
- NSString* jsToInject = [NSString stringWithFormat:jsWrapper,
sourceString];
+ NSString *sourceString = [sourceArrayString
substringWithRange:NSMakeRange(1, [sourceArrayString length] - 2)];
+ NSString *jsToInject = [NSString stringWithFormat:jsWrapper,
sourceString];
[self evaluateJavaScript:jsToInject];
}
} else {
@@ -359,8 +360,9 @@ static CDVWKInAppBrowser* instance = nil;
//Synchronus helper for javascript evaluation
-- (void)evaluateJavaScript:(NSString *)script {
- __block NSString* _script = script;
+- (void)evaluateJavaScript:(NSString *)script
+{
+ __block NSString *_script = script;
[self.inAppBrowserViewController.webView evaluateJavaScript:script
completionHandler:^(id result, NSError *error) {
if (error == nil) {
if (result != nil) {
@@ -372,9 +374,9 @@ static CDVWKInAppBrowser* instance = nil;
}];
}
-- (void)injectScriptCode:(CDVInvokedUrlCommand*)command
+- (void)injectScriptCode:(CDVInvokedUrlCommand *)command
{
- NSString* jsWrapper = nil;
+ NSString *jsWrapper = nil;
if ((command.callbackId != nil) && ![command.callbackId
isEqualToString:@"INVALID"]) {
jsWrapper = [NSString
stringWithFormat:@"_cdvMessageHandler('%@',JSON.stringify([eval(%%@)]));",
command.callbackId];
@@ -382,9 +384,9 @@ static CDVWKInAppBrowser* instance = nil;
[self injectDeferredObject:[command argumentAtIndex:0]
withWrapper:jsWrapper];
}
-- (void)injectScriptFile:(CDVInvokedUrlCommand*)command
+- (void)injectScriptFile:(CDVInvokedUrlCommand *)command
{
- NSString* jsWrapper;
+ NSString *jsWrapper;
if ((command.callbackId != nil) && ![command.callbackId
isEqualToString:@"INVALID"]) {
jsWrapper = [NSString stringWithFormat:@"(function(d) { var c =
d.createElement('script'); c.src = %%@; c.onload = function() {
_cdvMessageHandler('%@'); }; d.body.appendChild(c); })(document)",
command.callbackId];
@@ -394,9 +396,9 @@ static CDVWKInAppBrowser* instance = nil;
[self injectDeferredObject:[command argumentAtIndex:0]
withWrapper:jsWrapper];
}
-- (void)injectStyleCode:(CDVInvokedUrlCommand*)command
+- (void)injectStyleCode:(CDVInvokedUrlCommand *)command
{
- NSString* jsWrapper;
+ NSString *jsWrapper;
if ((command.callbackId != nil) && ![command.callbackId
isEqualToString:@"INVALID"]) {
jsWrapper = [NSString stringWithFormat:@"(function(d) { var c =
d.createElement('style'); c.innerHTML = %%@; c.onload = function() {
_cdvMessageHandler('%@'); }; d.body.appendChild(c); })(document)",
command.callbackId];
@@ -406,9 +408,9 @@ static CDVWKInAppBrowser* instance = nil;
[self injectDeferredObject:[command argumentAtIndex:0]
withWrapper:jsWrapper];
}
-- (void)injectStyleFile:(CDVInvokedUrlCommand*)command
+- (void)injectStyleFile:(CDVInvokedUrlCommand *)command
{
- NSString* jsWrapper;
+ NSString *jsWrapper;
if ((command.callbackId != nil) && ![command.callbackId
isEqualToString:@"INVALID"]) {
jsWrapper = [NSString stringWithFormat:@"(function(d) { var c =
d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%@;
c.onload = function() { _cdvMessageHandler('%@'); }; d.body.appendChild(c);
})(document)", command.callbackId];
@@ -440,32 +442,32 @@ static CDVWKInAppBrowser* instance = nil;
* to the InAppBrowser plugin. Care has been taken that other callbacks cannot
be triggered, and that no
* other code execution is possible.
*/
-- (void)webView:(WKWebView *)theWebView
decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
-
- NSURL* url = navigationAction.request.URL;
- NSURL* mainDocumentURL = navigationAction.request.mainDocumentURL;
+- (void)webView:(WKWebView *)theWebView
decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
+{
+ NSURL *url = navigationAction.request.URL;
+ NSURL *mainDocumentURL = navigationAction.request.mainDocumentURL;
BOOL isTopLevelNavigation = [url isEqual:mainDocumentURL];
BOOL shouldStart = YES;
BOOL useBeforeLoad = NO;
- NSString* httpMethod = navigationAction.request.HTTPMethod;
- NSString* errorMessage = nil;
+ NSString *httpMethod = navigationAction.request.HTTPMethod;
+ NSString *errorMessage = nil;
- if([_beforeload isEqualToString:@"post"]){
+ if ([_beforeload isEqualToString:@"post"]) {
//TODO handle POST requests by preserving POST data then remove this
condition
errorMessage = @"beforeload doesn't yet support POST requests";
}
- else if(isTopLevelNavigation && (
+ else if (isTopLevelNavigation && (
[_beforeload isEqualToString:@"yes"]
|| ([_beforeload isEqualToString:@"get"] && [httpMethod
isEqualToString:@"GET"])
// TODO comment in when POST requests are handled
// || ([_beforeload isEqualToString:@"post"] && [httpMethod
isEqualToString:@"POST"])
- )){
+ )) {
useBeforeLoad = YES;
}
// When beforeload, on first URL change, initiate JS callback. Only after
the beforeload event, continue.
if (_waitForBeforeload && useBeforeLoad) {
- CDVPluginResult* pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
+ CDVPluginResult *pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"beforeload", @"url":[url absoluteString]}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
@@ -474,24 +476,23 @@ static CDVWKInAppBrowser* instance = nil;
return;
}
- if(errorMessage != nil){
+ if (errorMessage != nil) {
NSLog(@"%@", errorMessage);
- CDVPluginResult* pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_ERROR
+ CDVPluginResult *pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_ERROR
messageAsDictionary:@{@"type":@"loaderror", @"url":[url absoluteString],
@"code": @"-1", @"message": errorMessage}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:self.callbackId];
}
//if is an app store, tel, sms, mailto or geo link, let the system handle
it, otherwise it fails to load it
- NSArray * allowedSchemes = @[@"itms-appss", @"itms-apps", @"tel", @"sms",
@"mailto", @"geo"];
+ NSArray *allowedSchemes = @[@"itms-appss", @"itms-apps", @"tel", @"sms",
@"mailto", @"geo"];
if ([allowedSchemes containsObject:[url scheme]]) {
[theWebView stopLoading];
[self openInSystem:url];
shouldStart = NO;
- }
- else if ((self.callbackId != nil) && isTopLevelNavigation) {
+ } else if ((self.callbackId != nil) && isTopLevelNavigation) {
// Send a loadstart event for each top-level navigation (includes
redirects).
- CDVPluginResult* pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
+ CDVPluginResult *pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"loadstart", @"url":[url absoluteString]}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
@@ -502,35 +503,35 @@ static CDVWKInAppBrowser* instance = nil;
_waitForBeforeload = YES;
}
- if(shouldStart){
+ if (shouldStart) {
// Fix GH-417 & GH-424: Handle non-default target attribute
// Based on https://stackoverflow.com/a/25713070/777265
- if (!navigationAction.targetFrame){
+ if (!navigationAction.targetFrame) {
[theWebView loadRequest:navigationAction.request];
decisionHandler(WKNavigationActionPolicyCancel);
- }else{
+ } else {
decisionHandler(WKNavigationActionPolicyAllow);
}
- }else{
+ } else {
decisionHandler(WKNavigationActionPolicyCancel);
}
}
#pragma mark WKScriptMessageHandler delegate
-- (void)userContentController:(nonnull WKUserContentController
*)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage
*)message {
-
- CDVPluginResult* pluginResult = nil;
+- (void)userContentController:(nonnull WKUserContentController
*)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage
*)message
+{
+ CDVPluginResult *pluginResult = nil;
- if([message.body isKindOfClass:[NSDictionary class]]){
- NSDictionary* messageContent = (NSDictionary*) message.body;
- NSString* scriptCallbackId = messageContent[@"id"];
+ if ([message.body isKindOfClass:[NSDictionary class]]) {
+ NSDictionary *messageContent = (NSDictionary *) message.body;
+ NSString *scriptCallbackId = messageContent[@"id"];
- if([messageContent objectForKey:@"d"]){
- NSString* scriptResult = messageContent[@"d"];
- NSError* __autoreleasing error = nil;
- NSData* decodedResult = [NSJSONSerialization
JSONObjectWithData:[scriptResult dataUsingEncoding:NSUTF8StringEncoding]
options:kNilOptions error:&error];
+ if ([messageContent objectForKey:@"d"]) {
+ NSString *scriptResult = messageContent[@"d"];
+ NSError * __autoreleasing error = nil;
+ NSData *decodedResult = [NSJSONSerialization
JSONObjectWithData:[scriptResult dataUsingEncoding:NSUTF8StringEncoding]
options:kNilOptions error:&error];
if ((error == nil) && [decodedResult isKindOfClass:[NSArray
class]]) {
- pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK messageAsArray:(NSArray*)decodedResult];
+ pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK messageAsArray:(NSArray *)decodedResult];
} else {
pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_JSON_EXCEPTION];
}
@@ -538,40 +539,40 @@ static CDVWKInAppBrowser* instance = nil;
pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK messageAsArray:@[]];
}
[self.commandDelegate sendPluginResult:pluginResult
callbackId:scriptCallbackId];
- }else if(self.callbackId != nil){
+ } else if (self.callbackId != nil) {
// Send a message event
- NSString* messageContent = (NSString*) message.body;
- NSError* __autoreleasing error = nil;
- NSData* decodedResult = [NSJSONSerialization
JSONObjectWithData:[messageContent dataUsingEncoding:NSUTF8StringEncoding]
options:kNilOptions error:&error];
+ NSString *messageContent = (NSString *) message.body;
+ NSError * __autoreleasing error = nil;
+ NSData *decodedResult = [NSJSONSerialization
JSONObjectWithData:[messageContent dataUsingEncoding:NSUTF8StringEncoding]
options:kNilOptions error:&error];
if (error == nil) {
- NSMutableDictionary* dResult = [NSMutableDictionary new];
+ NSMutableDictionary *dResult = [NSMutableDictionary new];
[dResult setValue:@"message" forKey:@"type"];
[dResult setObject:decodedResult forKey:@"data"];
- CDVPluginResult* pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dResult];
+ CDVPluginResult *pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dResult];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:self.callbackId];
}
}
}
-- (void)didStartProvisionalNavigation:(WKWebView*)theWebView
+- (void)didStartProvisionalNavigation:(WKWebView *)theWebView
{
NSLog(@"didStartProvisionalNavigation");
// self.inAppBrowserViewController.currentURL = theWebView.URL;
}
-- (void)didFinishNavigation:(WKWebView*)theWebView
+- (void)didFinishNavigation:(WKWebView *)theWebView
{
if (self.callbackId != nil) {
- NSString* url = [theWebView.URL absoluteString];
- if(url == nil){
- if(self.inAppBrowserViewController.currentURL != nil){
+ NSString *url = [theWebView.URL absoluteString];
+ if (url == nil) {
+ if (self.inAppBrowserViewController.currentURL != nil) {
url = [self.inAppBrowserViewController.currentURL
absoluteString];
- }else{
+ } else {
url = @"";
}
}
- CDVPluginResult* pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
+ CDVPluginResult *pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"loadstop", @"url":url}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
@@ -579,18 +580,18 @@ static CDVWKInAppBrowser* instance = nil;
}
}
-- (void)webView:(WKWebView*)theWebView didFailNavigation:(NSError*)error
+- (void)webView:(WKWebView *)theWebView didFailNavigation:(NSError *)error
{
if (self.callbackId != nil) {
- NSString* url = [theWebView.URL absoluteString];
- if(url == nil){
- if(self.inAppBrowserViewController.currentURL != nil){
+ NSString *url = [theWebView.URL absoluteString];
+ if (url == nil) {
+ if (self.inAppBrowserViewController.currentURL != nil) {
url = [self.inAppBrowserViewController.currentURL
absoluteString];
- }else{
+ } else {
url = @"";
}
}
- CDVPluginResult* pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_ERROR
+ CDVPluginResult *pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_ERROR
messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber
numberWithInteger:error.code], @"message": error.localizedDescription}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
@@ -601,7 +602,7 @@ static CDVWKInAppBrowser* instance = nil;
- (void)browserExit
{
if (self.callbackId != nil) {
- CDVPluginResult* pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
+ CDVPluginResult *pluginResult = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"exit"}];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:self.callbackId];
self.callbackId = nil;
@@ -637,7 +638,7 @@ static CDVWKInAppBrowser* instance = nil;
CGFloat lastReducedStatusBarHeight = 0.0;
BOOL isExiting = FALSE;
-- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions
andSettings:(NSDictionary *)settings
+- (id)initWithBrowserOptions:(CDVInAppBrowserOptions *)browserOptions
andSettings:(NSDictionary *)settings
{
self = [super init];
if (self != nil) {
@@ -645,22 +646,22 @@ BOOL isExiting = FALSE;
_settings = settings;
self.webViewUIDelegate = [[CDVWKInAppBrowserUIDelegate alloc]
initWithTitle:[[NSBundle mainBundle]
objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
[self.webViewUIDelegate setViewController:self];
-
[self createViews];
}
return self;
}
--(void)dealloc {
+- (void)dealloc
+{
//NSLog(@"dealloc");
}
- (void)createViews
{
// We create the views in code for primarily for ease of upgrades and not
requiring an external .xib to be included
- WKUserContentController* userContentController = [[WKUserContentController
alloc] init];
- WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc]
init];
+ WKUserContentController *userContentController = [[WKUserContentController
alloc] init];
+ WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc]
init];
NSString *userAgent = configuration.applicationNameForUserAgent;
if ([self settingForKey:@"OverrideUserAgent"] == nil &&
@@ -681,7 +682,7 @@ BOOL isExiting = FALSE;
configuration.allowsInlineMediaPlayback =
_browserOptions.allowinlinemediaplayback;
configuration.ignoresViewportScaleLimits =
_browserOptions.enableviewportscale;
- if(_browserOptions.mediaplaybackrequiresuseraction == YES) {
+ if (_browserOptions.mediaplaybackrequiresuseraction == YES) {
configuration.mediaTypesRequiringUserActionForPlayback =
WKAudiovisualMediaTypeAll;
} else {
configuration.mediaTypesRequiringUserActionForPlayback =
WKAudiovisualMediaTypeNone;
@@ -791,12 +792,12 @@ BOOL isExiting = FALSE;
self.closeButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
action:@selector(close)];
self.closeButton.enabled = YES;
- UIBarButtonItem* flexibleSpaceButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil
action:nil];
+ UIBarButtonItem *flexibleSpaceButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil
action:nil];
- UIBarButtonItem* fixedSpaceButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil
action:nil];
+ UIBarButtonItem *fixedSpaceButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil
action:nil];
fixedSpaceButton.width = 20;
- NSString* frontArrowString = NSLocalizedString(@"►", nil); // create arrow
from Unicode char
+ NSString *frontArrowString = NSLocalizedString(@"►", nil); // create arrow
from Unicode char
self.forwardButton = [[UIBarButtonItem alloc]
initWithTitle:frontArrowString style:UIBarButtonItemStylePlain target:self
action:@selector(goForward:)];
self.forwardButton.enabled = YES;
self.forwardButton.imageInsets = UIEdgeInsetsZero;
@@ -804,7 +805,7 @@ BOOL isExiting = FALSE;
self.forwardButton.tintColor = [self
colorFromHexString:_browserOptions.navigationbuttoncolor];
}
- NSString* backArrowString = NSLocalizedString(@"◄", nil); // create arrow
from Unicode char
+ NSString *backArrowString = NSLocalizedString(@"◄", nil); // create arrow
from Unicode char
self.backButton = [[UIBarButtonItem alloc] initWithTitle:backArrowString
style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)];
self.backButton.enabled = YES;
self.backButton.imageInsets = UIEdgeInsetsZero;
@@ -937,17 +938,18 @@ BOOL isExiting = FALSE;
}
}
-- (id)settingForKey:(NSString*)key
+- (id)settingForKey:(NSString *)key
{
return [_settings objectForKey:[key lowercaseString]];
}
-- (void) setWebViewFrame : (CGRect) frame {
+- (void)setWebViewFrame:(CGRect)frame
+{
NSLog(@"Setting the WebView's frame to %@", NSStringFromCGRect(frame));
[self.webView setFrame:frame];
}
-- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int)
buttonIndex
+- (void)setCloseButtonTitle:(NSString *)title withColor:(NSString
*)colorString atIndex:(int)buttonIndex
{
// the advantage of using UIBarButtonSystemItemDone is the system will
localize it for you automatically
// but, if you want to set this yourself, knock yourself out (we can't set
the title for a system Done button, so we have to create a new one)
@@ -958,7 +960,7 @@ BOOL isExiting = FALSE;
// If color on closebutton is requested then initialize with that that
color, otherwise use initialize with default
self.closeButton.tintColor = colorString != nil ? [self
colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0
green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1];
- NSMutableArray* items = [self.toolbar.items mutableCopy];
+ NSMutableArray *items = [self.toolbar.items mutableCopy];
[items replaceObjectAtIndex:buttonIndex withObject:self.closeButton];
[self.toolbar setItems:items];
}
@@ -970,7 +972,7 @@ BOOL isExiting = FALSE;
[self.view layoutIfNeeded];
}
-- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition
+- (void)showToolBar:(BOOL)show atPosition:(NSString *)toolbarPosition
{
self.toolbar.hidden = !show;
_browserOptions.toolbarposition = toolbarPosition; // keep state
consistent if needed
@@ -994,7 +996,7 @@ BOOL isExiting = FALSE;
- (UIStatusBarStyle)preferredStatusBarStyle
{
- NSString* statusBarStylePreference = [self
settingForKey:@"InAppBrowserStatusBarStyle"];
+ NSString *statusBarStylePreference = [self
settingForKey:@"InAppBrowserStatusBarStyle"];
if (statusBarStylePreference && [statusBarStylePreference
isEqualToString:@"lightcontent"]) {
return UIStatusBarStyleLightContent;
} else if (statusBarStylePreference && [statusBarStylePreference
isEqualToString:@"darkcontent"]) {
@@ -1008,7 +1010,8 @@ BOOL isExiting = FALSE;
}
}
-- (BOOL)prefersStatusBarHidden {
+- (BOOL)prefersStatusBarHidden
+{
return NO;
}
@@ -1016,7 +1019,7 @@ BOOL isExiting = FALSE;
{
self.currentURL = nil;
- __weak UIViewController* weakSelf = self;
+ __weak UIViewController *weakSelf = self;
// Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{
@@ -1030,12 +1033,12 @@ BOOL isExiting = FALSE;
});
}
-- (void)navigateTo:(NSURL*)url
+- (void)navigateTo:(NSURL *)url
{
if ([url.scheme isEqualToString:@"file"]) {
[self.webView loadFileURL:url allowingReadAccessToURL:url];
} else {
- NSURLRequest* request = [NSURLRequest requestWithURL:url];
+ NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}
}
@@ -1053,7 +1056,8 @@ BOOL isExiting = FALSE;
// Helper function to convert hex color string to UIColor
// Assumes input like "#00FF00" (#RRGGBB).
// Taken from
https://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string
-- (UIColor *)colorFromHexString:(NSString *)hexString {
+- (UIColor *)colorFromHexString:(NSString *)hexString
+{
unsigned rgbValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexString];
[scanner setScanLocation:1]; // bypass '#' character
@@ -1070,7 +1074,7 @@ BOOL isExiting = FALSE;
self.backButton.enabled = theWebView.canGoBack;
self.forwardButton.enabled = theWebView.canGoForward;
- if(!_browserOptions.hidespinner) [self.spinner startAnimating];
+ if (!_browserOptions.hidespinner) [self.spinner startAnimating];
return [self.navigationDelegate didStartProvisionalNavigation:theWebView];
}
@@ -1091,42 +1095,38 @@ BOOL isExiting = FALSE;
- (void)webView:(WKWebView *)theWebView didFinishNavigation:(WKNavigation
*)navigation
{
// update url, stop spinner, update back/forward
-
self.addressLabel.text = [self.currentURL absoluteString];
self.backButton.enabled = theWebView.canGoBack;
self.forwardButton.enabled = theWebView.canGoForward;
theWebView.scrollView.contentInset = UIEdgeInsetsZero;
-
[self.spinner stopAnimating];
-
[self.navigationDelegate didFinishNavigation:theWebView];
}
-- (void)webView:(WKWebView*)theWebView failedNavigation:(NSString*)
delegateName withError:(nonnull NSError *)error{
+- (void)webView:(WKWebView *)theWebView failedNavigation:(NSString *)
delegateName withError:(nonnull NSError *)error
+{
// log fail message, stop spinner, update back/forward
NSLog(@"webView:%@ - %ld: %@", delegateName, (long)error.code, [error
localizedDescription]);
-
self.backButton.enabled = theWebView.canGoBack;
self.forwardButton.enabled = theWebView.canGoForward;
[self.spinner stopAnimating];
-
self.addressLabel.text = NSLocalizedString(@"Load Error", nil);
-
[self.navigationDelegate webView:theWebView didFailNavigation:error];
}
-- (void)webView:(WKWebView*)theWebView didFailNavigation:(null_unspecified
WKNavigation *)navigation withError:(nonnull NSError *)error
+- (void)webView:(WKWebView *)theWebView didFailNavigation:(null_unspecified
WKNavigation *)navigation withError:(nonnull NSError *)error
{
[self webView:theWebView failedNavigation:@"didFailNavigation"
withError:error];
}
-- (void)webView:(WKWebView*)theWebView
didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation
withError:(nonnull NSError *)error
+- (void)webView:(WKWebView *)theWebView
didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation
withError:(nonnull NSError *)error
{
[self webView:theWebView failedNavigation:@"didFailProvisionalNavigation"
withError:error];
}
#pragma mark WKScriptMessageHandler delegate
-- (void)userContentController:(nonnull WKUserContentController
*)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage
*)message {
+- (void)userContentController:(nonnull WKUserContentController
*)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage
*)message
+{
if (![message.name isEqualToString:IAB_BRIDGE_NAME]) {
return;
}
@@ -1155,7 +1155,8 @@ BOOL isExiting = FALSE;
#pragma mark UIAdaptivePresentationControllerDelegate
-- (void)presentationControllerWillDismiss:(UIPresentationController
*)presentationController {
+- (void)presentationControllerWillDismiss:(UIPresentationController
*)presentationController
+{
isExiting = TRUE;
}
diff --git a/src/ios/CDVWKInAppBrowserUIDelegate.h
b/src/ios/CDVWKInAppBrowserUIDelegate.h
index 6c3d89f..bc4adf8 100644
--- a/src/ios/CDVWKInAppBrowserUIDelegate.h
+++ b/src/ios/CDVWKInAppBrowserUIDelegate.h
@@ -21,12 +21,12 @@
@interface CDVWKInAppBrowserUIDelegate : NSObject <WKUIDelegate>{
@private
- UIViewController* _viewController;
+ UIViewController *_viewController;
}
-@property (nonatomic, copy) NSString* title;
+@property (nonatomic, copy) NSString *title;
-- (instancetype)initWithTitle:(NSString*)title;
--(void) setViewController:(UIViewController*) viewController;
+- (instancetype)initWithTitle:(NSString *)title;
+-(void) setViewController:(UIViewController *) viewController;
@end
diff --git a/src/ios/CDVWKInAppBrowserUIDelegate.m
b/src/ios/CDVWKInAppBrowserUIDelegate.m
index 87879af..76ca5d0 100644
--- a/src/ios/CDVWKInAppBrowserUIDelegate.m
+++ b/src/ios/CDVWKInAppBrowserUIDelegate.m
@@ -21,7 +21,7 @@
@implementation CDVWKInAppBrowserUIDelegate
-- (instancetype)initWithTitle:(NSString*)title
+- (instancetype)initWithTitle:(NSString *)title
{
self = [super init];
if (self) {
@@ -31,16 +31,16 @@
return self;
}
-- (void) webView:(WKWebView*)webView
runJavaScriptAlertPanelWithMessage:(NSString*)message
- initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void
(^)(void))completionHandler
+- (void)webView:(WKWebView *)webView
runJavaScriptAlertPanelWithMessage:(NSString *)message
+initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void
(^)(void))completionHandler
{
- UIAlertController* alert = [UIAlertController
alertControllerWithTitle:self.title
+ UIAlertController *alert = [UIAlertController
alertControllerWithTitle:self.title
message:message
preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK")
+ UIAlertAction *ok = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK")
style:UIAlertActionStyleDefault
- handler:^(UIAlertAction* action)
+ handler:^(UIAlertAction *action)
{
completionHandler();
[alert dismissViewControllerAnimated:YES completion:nil];
@@ -51,16 +51,16 @@
[[self getViewController] presentViewController:alert animated:YES
completion:nil];
}
-- (void) webView:(WKWebView*)webView
runJavaScriptConfirmPanelWithMessage:(NSString*)message
- initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(BOOL
result))completionHandler
+- (void)webView:(WKWebView *)webView
runJavaScriptConfirmPanelWithMessage:(NSString *)message
+initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL
result))completionHandler
{
- UIAlertController* alert = [UIAlertController
alertControllerWithTitle:self.title
+ UIAlertController *alert = [UIAlertController
alertControllerWithTitle:self.title
message:message
preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK")
+ UIAlertAction *ok = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK")
style:UIAlertActionStyleDefault
- handler:^(UIAlertAction* action)
+ handler:^(UIAlertAction *action)
{
completionHandler(YES);
[alert dismissViewControllerAnimated:YES completion:nil];
@@ -68,9 +68,9 @@
[alert addAction:ok];
- UIAlertAction* cancel = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
+ UIAlertAction *cancel = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
style:UIAlertActionStyleDefault
- handler:^(UIAlertAction*
action)
+ handler:^(UIAlertAction
*action)
{
completionHandler(NO);
[alert dismissViewControllerAnimated:YES completion:nil];
@@ -80,46 +80,46 @@
[[self getViewController] presentViewController:alert animated:YES
completion:nil];
}
-- (void) webView:(WKWebView*)webView
runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
- defaultText:(NSString*)defaultText
initiatedByFrame:(WKFrameInfo*)frame
- completionHandler:(void (^)(NSString* result))completionHandler
+- (void)webView:(WKWebView *)webView
runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt
+defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame
+completionHandler:(void (^)(NSString *result))completionHandler
{
- UIAlertController* alert = [UIAlertController
alertControllerWithTitle:self.title
+ UIAlertController *alert = [UIAlertController
alertControllerWithTitle:self.title
message:prompt
preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK")
+ UIAlertAction *ok = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK")
style:UIAlertActionStyleDefault
- handler:^(UIAlertAction* action)
+ handler:^(UIAlertAction *action)
{
- completionHandler(((UITextField*)alert.textFields[0]).text);
+ completionHandler(((UITextField *)alert.textFields[0]).text);
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
- UIAlertAction* cancel = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
+ UIAlertAction *cancel = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
style:UIAlertActionStyleDefault
- handler:^(UIAlertAction*
action)
+ handler:^(UIAlertAction
*action)
{
completionHandler(nil);
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:cancel];
- [alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
+ [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.text = defaultText;
}];
[[self getViewController] presentViewController:alert animated:YES
completion:nil];
}
--(UIViewController*) getViewController
+-(UIViewController *) getViewController
{
return _viewController;
}
--(void) setViewController:(UIViewController*) viewController
+-(void) setViewController:(UIViewController *) viewController
{
_viewController = viewController;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]