iOS SDK location services

ios

#1

I’m using the MoPub iOS SDK (v3.3) to integrate ads in our app. Looking at the MoPub.h header, it looks like this property should control whether the app uses the device’s location or not:

/**
 * A Boolean value indicating whether the MoPub SDK should use Core Location APIs to automatically
 * derive targeting information for location-based ads.
 *
 * When set to NO, the SDK will not attempt to determine device location. When set to YES, the
 * SDK will periodically try to listen for location updates in order to request location-based ads.
 * This only occurs if location services are enabled and the user has already authorized the use
 * of location services for the application. The default value is YES.
 *
 * @param enabled A Boolean value indicating whether the SDK should listen for location updates.
 */
@property (nonatomic, assign) BOOL locationUpdatesEnabled;

But, when I leave that flag to its default (YES), or explicitly set it to YES, I still see this in the console logs:

MOPUB: Will not start location updates: the application is not authorized for location services.

And in Settings.app, I see no entry for my app under the Location Services Privacy settings.

Is the idea that I need to explicitly create a CLLocationManager myself, and try to request a location, in order for this to work?

Note: I have added the appropriate location frameworks to the app build settings in Xcode.


#2

Hey n8r0n74,

Please see:

If you have locationUpdatesEnabled set to YES, but are getting that error, that means the below is failing.

![self isAuthorizedStatus:[CLLocationManager authorizationStatus]]

Please see the documentation for authorization here:
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html

Let us know if you still experience this issue or have any further questions.

Thanks,
Edward


#3

Thanks, Edward. Ok, so I just want to be clear … this is just the normal need for location authorization from the user?

I guess I would have thought that the MoPub SDK would have requested authorization, if the app didn’t have it by the time it got to the code you highlighted above. Obviously, that’s not what the header says :smile:

I suppose all my apps before now that used MoPub also explicitly used location services, so my code already requested authorization before MoPub code needed it. This current app has no location features, outside of what MoPub uses.

Thanks!


#4

Yes. This is just the location authorization required by the user. MoPub uses location for ad targeting, so this has to be enabled.

Edward