From 66806697162d44aef4fd50bf47c8ade72d5566e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Thu, 26 Mar 2015 15:44:58 -0700 Subject: [PATCH 1/2] Safely call `-[UIApplication isRegisteredForRemoteNotifications]` Fixes #1117. --- platform/ios/MGLMapView.mm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index a4604bc58..8b8d90299 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -365,10 +365,12 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ NSMutableDictionary *evt = [[NSMutableDictionary alloc] init]; - [evt setValue:[[NSNumber alloc] initWithDouble:mbglMap->getLatLng().latitude] forKey:@"lat"]; - [evt setValue:[[NSNumber alloc] initWithDouble:mbglMap->getLatLng().longitude] forKey:@"lng"]; - [evt setValue:[[NSNumber alloc] initWithDouble:mbglMap->getZoom()] forKey:@"zoom"]; - [evt setValue:[[NSNumber alloc] initWithBool:[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]] forKey:@"enabled.push"]; + [evt setValue:@(mbglMap->getLatLng().latitude) forKey:@"lat"]; + [evt setValue:@(mbglMap->getLatLng().longitude) forKey:@"lng"]; + [evt setValue:@(mbglMap->getZoom()) forKey:@"zoom"]; + BOOL isRegisteredForRemoteNotifications = ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)] + && [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]); + [evt setValue:@(isRegisteredForRemoteNotifications) forKey:@"enabled.push"]; NSString *email = @"Unknown"; Class MFMailComposeViewController = NSClassFromString(@"MFMailComposeViewController"); From c4d19203b7fa80177af0f1bf6ad0647e539b7b45 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Thu, 26 Mar 2015 20:24:22 -0700 Subject: [PATCH 2/2] iOS 7 isRegisteredForRemoteNotifications support --- platform/ios/MGLMapView.mm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 8b8d90299..dd04b7c46 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -368,8 +368,19 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; [evt setValue:@(mbglMap->getLatLng().latitude) forKey:@"lat"]; [evt setValue:@(mbglMap->getLatLng().longitude) forKey:@"lng"]; [evt setValue:@(mbglMap->getZoom()) forKey:@"zoom"]; - BOOL isRegisteredForRemoteNotifications = ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)] - && [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]); + + BOOL isRegisteredForRemoteNotifications; + if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) { + // iOS 8+ + isRegisteredForRemoteNotifications = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; + } else { + // iOS 7 + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; + isRegisteredForRemoteNotifications = (types == UIRemoteNotificationTypeNone) ? NO : YES; + #pragma clang diagnostic pop + } [evt setValue:@(isRegisteredForRemoteNotifications) forKey:@"enabled.push"]; NSString *email = @"Unknown";