0

I'm implementing the new core location permissions for iOS 8, but I would like to compile and ship using Xcode 5.1.1 and the iOS 7.1 SDK.

Specifically, I want to call the method "requestWhenInUseAuthorization" on CLLocationManager, which is only available in iOS 8.

What are the risks to doing it this way? Is this a good practice? Can I ignore the 'Undeclared Selector' warning?

// Warning: Undeclared Selector
SEL requestWhenInUse = @selector(requestWhenInUseAuthorization); 
if( [self.sharedLocationManager respondsToSelector:requestWhenInUse] )
{
    // Warning: May cause leak because selector is unknown
    [self.sharedLocationManager performSelector:requestWhenInUse];
}
[self.sharedLocationManager startUpdatingLocation];
CornPuff
  • 2,059
  • 20
  • 24

1 Answers1

2

Your code is fine. To suppress warnings, add

@interface CLLocationManager (iOS8Method)

- (void)requestWhenInUseAuthorization;

@end

then you can call the method

if( [self.sharedLocationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] )
{
    [self.sharedLocationManager requestWhenInUseAuthorization];
}

also read this question: performSelector may cause a leak because its selector is unknown

Community
  • 1
  • 1
Bryan Chen
  • 42,570
  • 18
  • 109
  • 136
  • It will be interesting to se if that passes Apple API testing. – zaph Aug 26 '14 at 21:02
  • @Zaph I can't see why it will have problem because it is public documented method now and `@interface` only tell compile this method exist without creating a category. – Bryan Chen Aug 26 '14 at 21:05
  • I said it will be interesting. I do see a reason. On a general level not all iOS8 APIs will work from iOS7 SDK. So either Apple validated which ones are safe and do work from iOS7 SDK and put that information into their testing tools to explicitly allow them or they need to deny all. Given that Apple seems to desire apps to move to the latest IOS version I bet on the deny all. – zaph Aug 26 '14 at 21:13