convert metrics BOOLs to strings internally

This commit is contained in:
Justin R. Miller
2015-03-27 00:17:42 -07:00
parent 4a4d9c1a2d
commit 1a8d6445d1
3 changed files with 31 additions and 16 deletions

View File

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

View File

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

View File

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