summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2015-03-27 00:17:42 -0700
committerJustin R. Miller <incanus@codesorcery.net>2015-03-27 00:17:42 -0700
commit1a8d6445d18741b399f381e3835c2362286582f6 (patch)
tree3d72fcb62fd9c34cd6c9ad7573a5a030e0796296
parent4a4d9c1a2d2b4e11735f8e5ccf0d0d7df567679b (diff)
downloadqtlocation-mapboxgl-1a8d6445d18741b399f381e3835c2362286582f6.tar.gz
convert metrics BOOLs to strings internally
-rw-r--r--include/mbgl/ios/MGLMapboxEvents.h2
-rw-r--r--platform/ios/MGLMapView.mm2
-rw-r--r--platform/ios/MGLMapboxEvents.m43
3 files changed, 31 insertions, 16 deletions
diff --git a/include/mbgl/ios/MGLMapboxEvents.h b/include/mbgl/ios/MGLMapboxEvents.h
index 541f21df43..6f994fea26 100644
--- a/include/mbgl/ios/MGLMapboxEvents.h
+++ b/include/mbgl/ios/MGLMapboxEvents.h
@@ -33,7 +33,7 @@ extern NSString *const MGLEventMapLocation;
// 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 92367a3cf2..31d84000ac 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -360,7 +360,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
@"lng": @(latLng.longitude),
@"zoom": @(zoom),
@"enabled.push": @([MGLMapboxEvents checkPushEnabled]),
- @"enabled.email": [MGLMapboxEvents checkEmailEnabled]
+ @"enabled.email": @([MGLMapboxEvents checkEmailEnabled])
}];
return YES;
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m
index 39470a97ff..1ce8288f5d 100644
--- a/platform/ios/MGLMapboxEvents.m
+++ b/platform/ios/MGLMapboxEvents.m
@@ -216,6 +216,22 @@ NSString *const MGLEventMapLocation = @"Location";
// use of +pushEvent:withAttributes:.
//
- (void) pushEvent:(NSString *)event withAttributes:(NSDictionary *)attributeDictionary {
+ // convert 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, ^{
@@ -546,21 +562,19 @@ NSString *const MGLEventMapLocation = @"Location";
// 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();
@@ -575,23 +589,24 @@ NSString *const MGLEventMapLocation = @"Location";
// 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();