feat: Add compile-time decision for disabling UIWebView
MODIFY
src/ios/GoogleMaps/PluginGroundOverlay.h
src/ios/GoogleMaps/PluginGroundOverlay.h
- (void)setBearing:(CDVInvokedUrlCommand*)command;
- (void)setZIndex:(CDVInvokedUrlCommand *)command;
- (void)_setImage:(GMSGroundOverlay *)layer urlStr:(NSString *)urlStr completionHandler:(void (^)(BOOL succeeded))completionHandler;
+- (void)_WKsetImage:(GMSGroundOverlay *)groundOverlay webview:(id)webview urlStr:(NSString *)urlStr completionHandler:(void (^)(BOOL succeeded))completionHandler;
- (void)downloadImageWithURL:(NSURL *)url completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock;
@end

MODIFY
src/ios/GoogleMaps/PluginGroundOverlay.m
src/ios/GoogleMaps/PluginGroundOverlay.m
// Get the current URL, then calculate the relative path.
CDVViewController *cdvViewController = (CDVViewController*)self.viewController;
id webview = cdvViewController.webView;
+ #if WK_WEB_VIEW_ONLY
+ [self _WKsetImage:groundOverlay webview:(webview) urlStr:(urlStr) completionHandler:completionHandler];
+ return;
+ #else
NSString *clsName = [webview className];
NSURL *url;
if ([clsName isEqualToString:@"UIWebView"]) {
currentURL = [currentURL stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
urlStr = [NSString stringWithFormat:@"file://%@/%@", currentURL, urlStr];
} else {
- //------------------------------------------
- // WKWebView URL is use http:// always
- //------------------------------------------
- dispatch_sync(dispatch_get_main_queue(), ^{
- NSURL *url = [webview URL];
- NSString *currentURL = url.absoluteString;
- if (![[url lastPathComponent] isEqualToString:@"/"]) {
- currentURL = [currentURL stringByDeletingLastPathComponent];
- }
-
- // remove page unchor (i.e index.html#page=test, index.html?key=value)
- NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:nil];
- currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
-
- // remove file name (i.e /index.html)
- regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:nil];
- currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
-
-
- NSString *urlStr2 = [NSString stringWithFormat:@"%@/%@", currentURL, urlStr];
- urlStr2 = [urlStr2 stringByReplacingOccurrencesOfString:@":/" withString:@"://"];
- urlStr2 = [urlStr2 stringByReplacingOccurrencesOfString:@":///" withString:@"://"];
- url = [NSURL URLWithString:urlStr2];
-
- [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
-
- if (!succeeded) {
- completionHandler(NO);
- return;
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
- groundOverlay.icon = image;
- completionHandler(YES);
- });
-
- }];
- });
+ [self _WKsetImage:groundOverlay webview:(webview) urlStr:(urlStr) completionHandler:completionHandler];
return;
}
+ #endif
} else {
urlStr = [NSString stringWithFormat:@"file://%@", urlStr];
}
}];
}
+}
+
+- (void)_WKsetImage:(GMSGroundOverlay *)groundOverlay webview:(id)webview urlStr:(NSString *)urlStr completionHandler:(void (^)(BOOL succeeded))completionHandler {
+ //------------------------------------------
+ // WKWebView URL is use http:// always
+ //------------------------------------------
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ NSURL *url = [webview URL];
+ NSString *currentURL = url.absoluteString;
+ if (![[url lastPathComponent] isEqualToString:@"/"]) {
+ currentURL = [currentURL stringByDeletingLastPathComponent];
+ }
+
+ // remove page unchor (i.e index.html#page=test, index.html?key=value)
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:nil];
+ currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
+
+ // remove file name (i.e /index.html)
+ regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:nil];
+ currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
+ NSString *urlStr2 = [NSString stringWithFormat:@"%@/%@", currentURL, urlStr];
+ urlStr2 = [urlStr2 stringByReplacingOccurrencesOfString:@":/" withString:@"://"];
+ urlStr2 = [urlStr2 stringByReplacingOccurrencesOfString:@":///" withString:@"://"];
+ url = [NSURL URLWithString:urlStr2];
+
+ [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
+
+ if (!succeeded) {
+ completionHandler(NO);
+ return;
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ groundOverlay.icon = image;
+ completionHandler(YES);
+ });
+
+ }];
+ });
}
/**

MODIFY
src/ios/GoogleMaps/PluginKmlOverlay.h
src/ios/GoogleMaps/PluginKmlOverlay.h
@property (nonatomic) BOOL initialized;
@property (nonatomic, strong) PluginMapViewController* mapCtrl;
- (void)create:(CDVInvokedUrlCommand*)command;
+- (NSString *)_WKcurrentUrl:(id)webview;
@end
@interface KmlParseClass : NSObject

MODIFY
src/ios/GoogleMaps/PluginKmlOverlay.m
src/ios/GoogleMaps/PluginKmlOverlay.m
NSString *clsName = [webview className];
NSURL *url;
NSString *currentURL;
+ #if WK_WEB_VIEW_ONLY
+ currentURL = [self _WKcurrentUrl:webview];
+ #else
if ([clsName isEqualToString:@"UIWebView"]) {
//------------------------------------------
// UIWebView
//------------------------------------------
url = ((UIWebView *)cdvViewController.webView).request.URL;
currentURL = url.absoluteString;
-
} else {
//------------------------------------------
// WKWebView
//------------------------------------------
- NSURL *url = [webview URL];
- currentURL = url.absoluteString;
- if (![[url lastPathComponent] isEqualToString:@"/"]) {
- currentURL = [currentURL stringByReplacingOccurrencesOfString:[url lastPathComponent] withString:@""];
+ currentURL = [self _WKcurrentUrl:webview];
}
+ #endif
}
// remove page unchor (i.e index.html#page=test, index.html?key=value)
regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:&error];
}
+- (NSString *)_WKcurrentUrl:(id)webview {
+ NSString *currentURL;
+ NSURL *url = [webview URL];
+ currentURL = url.absoluteString;
+ if (![[url lastPathComponent] isEqualToString:@"/"]) {
+ currentURL = [currentURL stringByReplacingOccurrencesOfString:[url lastPathComponent] withString:@""];
+ }
+ return currentURL;
+}
+
- (void)loadKml:(NSString *)urlStr completionBlock:(void (^)(BOOL succeeded, id result))completionBlock {
urlStr = [urlStr stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSError *error;

MODIFY
src/ios/GoogleMaps/PluginMarker.h
src/ios/GoogleMaps/PluginMarker.h
*/
- (void)_create:(NSString *)markerId markerOptions:(NSDictionary *)json callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock;
-(void)setIcon_:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock;
+- (void)_WksetIcon:(id)webview iconPath:(NSString *)iconPath iconCacheKey:(NSString *)iconCacheKey animation:(NSString *)animation width:(CGFloat)width height:(CGFloat)height marker:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock;
-(void)_removeMarker:(GMSMarker *)marker;

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
id webview = cdvViewController.webView;
NSString *clsName = [webview className];
NSURL *url;
+ #if WK_WEB_VIEW_ONLY
+ [self _WksetIcon:webview iconPath:(iconPath) iconCacheKey:(iconCacheKey) animation:(animation) width:(width) height:(height) marker:(marker) iconProperty:(iconProperty) callbackBlock:(callbackBlock)];
+ return;
+ #else
if ([clsName isEqualToString:@"UIWebView"]) {
url = ((UIWebView *)cdvViewController.webView).request.URL;
NSString *currentURL = url.absoluteString;
//------------------------------------------
// WKWebView
//------------------------------------------
-
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- NSURL *url = [webview URL];
- NSString *currentURL = url.absoluteString;
- //NSLog(@"currentURL = %@", url);
- if (![[url lastPathComponent] isEqualToString:@"/"]) {
- currentURL = [currentURL stringByDeletingLastPathComponent];
- }
- // remove page unchor (i.e index.html#page=test, index.html?key=value)
- NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:nil];
- currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
-
- // remove file name (i.e /index.html)
- regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:nil];
- currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
-
- //url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", currentURL, iconPath]];
- currentURL = [NSString stringWithFormat:@"%@/%@", currentURL, iconPath];
- currentURL = [currentURL regReplace:@"\\/\\.\\/" replaceTxt:@"/" options:0];
- currentURL = [currentURL regReplace:@"\\/+" replaceTxt:@"/" options:0];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@":/" withString:@"://"];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@":///" withString:@"://"];
- //NSLog(@"currentURL = %@", currentURL);
- url = [NSURL URLWithString:currentURL];
-
- //
- // Load the icon from over the internet
- //
- [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
-
- if (!succeeded) {
- dispatch_async(dispatch_get_main_queue(), ^{
- NSLog(@"[fail] url = %@", url);
- // The `visible` property
- if (iconProperty[@"visible"] == [NSNumber numberWithBool:true]) {
- marker.map = self.mapCtrl.map;
- } else if (iconProperty[@"visible"] == [NSNumber numberWithBool:false]) {
- marker.map = nil;
- }
- if ([[UIImageCache sharedInstance].iconCacheKeys objectForKey:iconCacheKey]) {
- [[UIImageCache sharedInstance].iconCacheKeys removeObjectForKey:iconCacheKey];
- }
-
- callbackBlock(NO, [NSString stringWithFormat:@"Can not load image from '%@'.", url]);
- });
- return;
- }
-
-
- if (self.mapCtrl.debuggable) {
- NSLog(@"[success] url = %@", url);
- }
-
- if (width && height) {
- image = [image resize:width height:height];
- }
-
- // Cache the icon image
- NSString *iconKey = [NSString stringWithFormat:@"marker_icon_%@", marker.userData];
- [[UIImageCache sharedInstance] cacheImage:image forKey:iconCacheKey];
- [self.mapCtrl.objects setObject:iconCacheKey forKey:iconKey];
- [[UIImageCache sharedInstance].iconCacheKeys setObject:[NSNumber numberWithInt:1] forKey:iconCacheKey];;
- //NSLog(@"--->confirm: key: %@, iconCacheKey : %@", iconKey, [self.mapCtrl.objects objectForKey:iconKey]);
-
- // Draw label
- if ([iconProperty objectForKey:@"label"]) {
- image = [self drawLabel:image labelOptions:[iconProperty objectForKey:@"label"]];
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
- marker.icon = image;
-
- // The `anchor` property for the icon
- if ([iconProperty valueForKey:@"anchor"]) {
- NSArray *points = [iconProperty valueForKey:@"anchor"];
- CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
- CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
- marker.groundAnchor = CGPointMake(anchorX, anchorY);
- }
-
-
- // The `infoWindowAnchor` property
- if ([iconProperty valueForKey:@"infoWindowAnchor"]) {
- NSArray *points = [iconProperty valueForKey:@"infoWindowAnchor"];
- CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
- CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
- marker.infoWindowAnchor = CGPointMake(anchorX, anchorY);
- }
-
- // The `visible` property
- if (iconProperty[@"visible"] == [NSNumber numberWithBool:true]) {
- marker.map = self.mapCtrl.map;
- } else if (iconProperty[@"visible"] == [NSNumber numberWithBool:false]) {
- marker.map = nil;
- }
-
-
- if (animation) {
- // Do animation, then send the result
- [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
- callbackBlock(YES, marker);
- }];
- } else {
- // Send the result
- callbackBlock(YES, marker);
- }
-
- });
-
-
- }];
-
-
-
-
- }];
-
+ [self _WksetIcon:webview iconPath:(iconPath) iconCacheKey:(iconCacheKey) animation:(animation) width:(width) height:(height) marker:(marker) iconProperty:(iconProperty) callbackBlock:(callbackBlock)];
return;
}
+ #endif
}
}
+- (void)_WksetIcon:(id)webview iconPath:(NSString *)iconPath iconCacheKey:(NSString *)iconCacheKey animation:(NSString *)animation width:(CGFloat)width height:(CGFloat)height marker:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ NSURL *url = [webview URL];
+ NSString *currentURL = url.absoluteString;
+ //NSLog(@"currentURL = %@", url);
+ if (![[url lastPathComponent] isEqualToString:@"/"]) {
+ currentURL = [currentURL stringByDeletingLastPathComponent];
+ }
+ // remove page unchor (i.e index.html#page=test, index.html?key=value)
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:nil];
+ currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
+
+ // remove file name (i.e /index.html)
+ regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:nil];
+ currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
+
+ //url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", currentURL, iconPath]];
+ currentURL = [NSString stringWithFormat:@"%@/%@", currentURL, iconPath];
+ currentURL = [currentURL regReplace:@"\\/\\.\\/" replaceTxt:@"/" options:0];
+ currentURL = [currentURL regReplace:@"\\/+" replaceTxt:@"/" options:0];
+ currentURL = [currentURL stringByReplacingOccurrencesOfString:@":/" withString:@"://"];
+ currentURL = [currentURL stringByReplacingOccurrencesOfString:@":///" withString:@"://"];
+ //NSLog(@"currentURL = %@", currentURL);
+ url = [NSURL URLWithString:currentURL];
+
+ //
+ // Load the icon from over the internet
+ //
+ [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
+
+ if (!succeeded) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSLog(@"[fail] url = %@", url);
+ // The `visible` property
+ if (iconProperty[@"visible"] == [NSNumber numberWithBool:true]) {
+ marker.map = self.mapCtrl.map;
+ } else if (iconProperty[@"visible"] == [NSNumber numberWithBool:false]) {
+ marker.map = nil;
+ }
+ if ([[UIImageCache sharedInstance].iconCacheKeys objectForKey:iconCacheKey]) {
+ [[UIImageCache sharedInstance].iconCacheKeys removeObjectForKey:iconCacheKey];
+ }
+
+ callbackBlock(NO, [NSString stringWithFormat:@"Can not load image from '%@'.", url]);
+ });
+ return;
+ }
+
+
+ if (self.mapCtrl.debuggable) {
+ NSLog(@"[success] url = %@", url);
+ }
+
+ if (width && height) {
+ image = [image resize:width height:height];
+ }
+
+ // Cache the icon image
+ NSString *iconKey = [NSString stringWithFormat:@"marker_icon_%@", marker.userData];
+ [[UIImageCache sharedInstance] cacheImage:image forKey:iconCacheKey];
+ [self.mapCtrl.objects setObject:iconCacheKey forKey:iconKey];
+ [[UIImageCache sharedInstance].iconCacheKeys setObject:[NSNumber numberWithInt:1] forKey:iconCacheKey];;
+ //NSLog(@"--->confirm: key: %@, iconCacheKey : %@", iconKey, [self.mapCtrl.objects objectForKey:iconKey]);
+
+ // Draw label
+ if ([iconProperty objectForKey:@"label"]) {
+ image = [self drawLabel:image labelOptions:[iconProperty objectForKey:@"label"]];
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ marker.icon = image;
+
+ // The `anchor` property for the icon
+ if ([iconProperty valueForKey:@"anchor"] && [iconProperty valueForKey:@"anchor"] != [NSNull null]) {
+ NSArray *points = [iconProperty valueForKey:@"anchor"];
+ CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
+ CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
+ marker.groundAnchor = CGPointMake(anchorX, anchorY);
+ }
+
+
+ // The `infoWindowAnchor` property
+ if ([iconProperty valueForKey:@"infoWindowAnchor"] && [iconProperty valueForKey:@"infoWindowAnchor"] != [NSNull null]) {
+ NSArray *points = [iconProperty valueForKey:@"infoWindowAnchor"];
+ CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
+ CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
+ marker.infoWindowAnchor = CGPointMake(anchorX, anchorY);
+ }
+
+ // The `visible` property
+ if (iconProperty[@"visible"] == [NSNumber numberWithBool:true]) {
+ marker.map = self.mapCtrl.map;
+ } else if (iconProperty[@"visible"] == [NSNumber numberWithBool:false]) {
+ marker.map = nil;
+ }
+
+
+ if (animation) {
+ // Do animation, then send the result
+ [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
+ callbackBlock(YES, marker);
+ }];
+ } else {
+ // Send the result
+ callbackBlock(YES, marker);
+ }
+
+ });
+ }];
+ }];
+}
+
- (UIImage *)drawLabel:(UIImage *) image labelOptions:(NSDictionary *)labelOptions {
NSString *text = [NSString stringWithFormat:@"%@", [labelOptions objectForKey:@"text"]];
if (text == nil) {

MODIFY
src/ios/GoogleMaps/PluginTileOverlay.m
src/ios/GoogleMaps/PluginTileOverlay.m
id webview = cdvViewController.webView;
NSString *clsName = [webview className];
NSURL *url;
+ #if WK_WEB_VIEW_ONLY
+ url = [webview URL];
+ #else
if ([clsName isEqualToString:@"UIWebView"]) {
url = ((UIWebView *)cdvViewController.webView).request.URL;
} else {
url = [webview URL];
}
+ #endif
NSString *webPageUrl = url.absoluteString;
[options setObject:webPageUrl forKey:@"webPageUrl"];
[options setObject:self.mapCtrl.overlayId forKey:@"mapId"];

MODIFY
src/ios/GoogleMaps/PluginUtil.h
src/ios/GoogleMaps/PluginUtil.h
@@ -58,7 +58,7 @@ typedef void (^MYCompletionHandler)(NSError *error);
// http://stackoverflow.com/questions/5272451/overriding-methods-using-categories-in-objective-c#5272612
//
@interface MainViewController (CDVViewController)
-#if CORDOVA_VERSION_MIN_REQUIRED < __CORDOVA_4_0_0
+#if CORDOVA_VERSION_MIN_REQUIRED < __CORDOVA_4_0_0 && !WK_WEB_VIEW_ONLY
- (void)webViewDidFinishLoad:(UIWebView*)theWebView;
#endif
@end

MODIFY
src/ios/GoogleMaps/PluginUtil.m
src/ios/GoogleMaps/PluginUtil.m
@@ -151,7 +151,7 @@ static char CAAnimationGroupBlockKey;
@implementation MainViewController (CDVViewController)
-#if CORDOVA_VERSION_MIN_REQUIRED < __CORDOVA_4_0_0
+#if CORDOVA_VERSION_MIN_REQUIRED < __CORDOVA_4_0_0 && !WK_WEB_VIEW_ONLY
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
theWebView.backgroundColor = [UIColor clearColor];

feat: Add compile-time decision for disabling UIWebView