Fix: App crashes on iOS if icon url is redirected to another url
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.3.9-beta-20180731-1540" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.3.9-beta-20180801-1016" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/ios/GoogleMaps/PluginGroundOverlay.m
src/ios/GoogleMaps/PluginGroundOverlay.m
NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:req];
if (cachedResponse != nil) {
UIImage *image = [[UIImage alloc] initWithData:cachedResponse.data];
+ if (image) {
completionBlock(YES, image);
return;
}
+ }
//-------------------------------------------------------------

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
{
[self.mapCtrl.executeQueue addOperationWithBlock:^{
- NSString *iconPath = url.absoluteString;
- NSString *uniqueKey = url.absoluteString;
-
- if ([iconPath hasPrefix:@"file://"]) {
- iconPath = [iconPath stringByReplacingOccurrencesOfString:@"file://" withString:@""];
- if (![iconPath hasPrefix:@"/"]) {
- iconPath = [NSString stringWithFormat:@"/%@", iconPath];
- }
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if (![fileManager fileExistsAtPath:iconPath]) {
- //if (self.mapCtrl.debuggable) {
- NSLog(@"(error)There is no file at '%@'.", iconPath);
- //}
- //[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
- completionBlock(NO, nil);
- return;
- }
-
- UIImage *image = [UIImage imageNamed:iconPath];
- if (image) {
- [[UIImageCache sharedInstance] cacheImage:image forKey:uniqueKey];
- completionBlock(YES, image);
- return;
- }
- }
-
-
-
NSURLRequest *req = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:5];
NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:req];
if (cachedResponse != nil) {
UIImage *image = [[UIImage alloc] initWithData:cachedResponse.data];
+ if (image) {
completionBlock(YES, image);
return;
}
+ }
+ NSString *uniqueKey = url.absoluteString;
UIImage *image = [[UIImageCache sharedInstance] getCachedImageForKey:uniqueKey];
if (image != nil) {
completionBlock(YES, image);

MODIFY
src/ios/GoogleMaps/PluginTileProvider.m
src/ios/GoogleMaps/PluginTileProvider.m
@@ -255,6 +255,7 @@ NSDictionary *debugAttributes;
NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:req];
if (cachedResponse != nil) {
UIImage *image = [[UIImage alloc] initWithData:cachedResponse.data];
+ if (image) {
if (self.isDebug) {
image = [self drawDebugInfoWithImage:image
x:x
@@ -265,11 +266,13 @@ NSDictionary *debugAttributes;
[receiver receiveTileWithX:x y:y zoom:zoom image:image];
return;
}
+ }
NSString *uniqueKey = url.absoluteString;
NSData *cache = [self.imgCache objectForKey:uniqueKey];
if (cache != nil) {
UIImage *image = [[UIImage alloc] initWithData:cache];
+ if (image) {
if (self.isDebug) {
image = [self drawDebugInfoWithImage:image
x:x
@@ -280,6 +283,7 @@ NSDictionary *debugAttributes;
[receiver receiveTileWithX:x y:y zoom:zoom image:image];
return;
}
+ }
//-------------------------------------------------------------
// Use NSURLSessionDataTask instead of [NSURLConnection sendAsynchronousRequest]

Fix: App crashes on iOS if icon url is redirected to another url #2369