Merge pull request #1135 from mapbox/1128-convert-booleans

fixes #1128: convert metrics BOOLs to strings internally
This commit is contained in:
Justin R. Miller
2015-03-27 10:47:03 -07:00
3 changed files with 31 additions and 16 deletions

View File

@@ -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.

View File

@@ -360,7 +360,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
MGLEventKeyLongitude: @(latLng.longitude),
MGLEventKeyZoomLevel: @(zoom),
MGLEventKeyPushEnabled: @([MGLMapboxEvents checkPushEnabled]),
MGLEventKeyEmailEnabled: [MGLMapboxEvents checkEmailEnabled]
MGLEventKeyEmailEnabled: @([MGLMapboxEvents checkEmailEnabled])
}];
return YES;

View File

@@ -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();