diff options
author | Justin R. Miller <incanus@users.noreply.github.com> | 2015-03-27 10:47:03 -0700 |
---|---|---|
committer | Justin R. Miller <incanus@users.noreply.github.com> | 2015-03-27 10:47:03 -0700 |
commit | e66e3c40050728c5d96c692003e87b675a9ef10b (patch) | |
tree | 996339af7b19fce7d69942a5d66723b8741cfeac | |
parent | 2e4d583d3cac794ea89563f5fc2691b8267a359e (diff) | |
parent | 2066e201ea5b90cc804c68c4e1cc8fb7eb5bea35 (diff) | |
download | qtlocation-mapboxgl-e66e3c40050728c5d96c692003e87b675a9ef10b.tar.gz |
Merge pull request #1135 from mapbox/1128-convert-booleans
fixes #1128: convert metrics BOOLs to strings internally
-rw-r--r-- | include/mbgl/ios/MGLMapboxEvents.h | 2 | ||||
-rw-r--r-- | platform/ios/MGLMapView.mm | 2 | ||||
-rw-r--r-- | platform/ios/MGLMapboxEvents.m | 43 |
3 files changed, 31 insertions, 16 deletions
diff --git a/include/mbgl/ios/MGLMapboxEvents.h b/include/mbgl/ios/MGLMapboxEvents.h index a105f33d03..0567eb6764 100644 --- a/include/mbgl/ios/MGLMapboxEvents.h +++ b/include/mbgl/ios/MGLMapboxEvents.h @@ -41,7 +41,7 @@ extern NSString *const MGLEventGestureRotateStart; // You can call these methods from any thread. // -+ (NSString *) checkEmailEnabled; ++ (BOOL) checkEmailEnabled; + (BOOL) checkPushEnabled; // You can call this method from any thread. diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 8466303ed5..6f3aec8038 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -360,7 +360,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; MGLEventKeyLongitude: @(latLng.longitude), MGLEventKeyZoomLevel: @(zoom), MGLEventKeyPushEnabled: @([MGLMapboxEvents checkPushEnabled]), - MGLEventKeyEmailEnabled: [MGLMapboxEvents checkEmailEnabled] + MGLEventKeyEmailEnabled: @([MGLMapboxEvents checkEmailEnabled]) }]; return YES; diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index a38251541b..94374b9da9 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -224,6 +224,22 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // use of +pushEvent:withAttributes:. // - (void) pushEvent:(NSString *)event withAttributes:(NSDictionary *)attributeDictionary { + // conve+rt any BOOL types to string values written out like JS + NSMutableDictionary *newAttributeDictionary = [NSMutableDictionary dictionaryWithCapacity:[attributeDictionary count]]; + NSString *key; + NSObject *value; + for (key in attributeDictionary) { + value = attributeDictionary[key]; + if ([value isKindOfClass:[NSNumber class]]) { + // if of character type, treat as bool + if (strncmp([(NSNumber *)value objCType], "c", 1) == 0) { + value = ([(NSNumber *)value boolValue] ? @"true" : @"false"); + } + } + newAttributeDictionary[key] = value; + } + attributeDictionary = newAttributeDictionary; + __weak MGLMapboxEvents *weakSelf = self; dispatch_async(_serialQueue, ^{ @@ -550,21 +566,19 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Can be called from any thread. // -+ (NSString *) checkEmailEnabled { - __block NSString *result; - - NSString *(^mailCheckBlock)(void) = ^{ - NSString *email = @"Unknown"; ++ (BOOL) checkEmailEnabled { + BOOL (^mailCheckBlock)(void) = ^{ + BOOL blockResult; Class MFMailComposeViewController = NSClassFromString(@"MFMailComposeViewController"); if (MFMailComposeViewController) { SEL canSendMail = NSSelectorFromString(@"canSendMail"); - BOOL sendMail = ((BOOL (*)(id, SEL))[MFMailComposeViewController methodForSelector:canSendMail]) - (MFMailComposeViewController, canSendMail); - email = [NSString stringWithFormat:@"%i", sendMail]; + blockResult = ((BOOL (*)(id, SEL))[MFMailComposeViewController methodForSelector:canSendMail])(MFMailComposeViewController, canSendMail); } - return email; + return blockResult; }; + __block BOOL result; + if ( ! [[NSThread currentThread] isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ result = mailCheckBlock(); @@ -579,23 +593,24 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Can be called from any thread. // + (BOOL) checkPushEnabled { - __block BOOL result; - BOOL (^pushCheckBlock)(void) = ^{ + BOOL blockResult; if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) { // iOS 8+ - result = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; + blockResult = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; } else { // iOS 7 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; - result = (types == UIRemoteNotificationTypeNone) ? NO : YES; + blockResult = (types == UIRemoteNotificationTypeNone) ? NO : YES; #pragma clang diagnostic pop } - return result; + return blockResult; }; + __block BOOL result; + if ( ! [[NSThread currentThread] isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ result = pushCheckBlock(); |