Location services in the IOS8

Source: Internet
Author: User

Location services in the IOS8

My app that's worked fine in iOS 7 doesn ' t work with the iOS 8 SDK.

CLLocationManagerDoesn ' t return a location, and I don't see my app under Settings > Location Services either. I did a Google search on the issue but nothing came up and what could is wrong?

My application runs well on the iOS7, but there is a problem on the iOS8.

In the iOS8, Cllocationmanager did not return an address, and I did not find the service in the Settings>location services, on Google also found no similar problems, where is the problem?

I ended up solving my own problem.

Apparently in IOS 8 SDK, requestAlwaysAuthorization (for background location) or (location only if foreground) call to is requestWhenInUseAuthorization CLLocationManager needed Before starting location updates.

There also needs to is NSLocationAlwaysUsageDescription or key in with a message to being displayed in the NSLocationWhenInUseUsageDescription Info.plist prompt. Adding these solved my problem.

Hope it helps someone else.

Finally, I solved the problem.

In the IOS8 SDK, you need additional requestalwaysauthorization (for background targeting) and requestwheninuseauthorization (as a foreground location), You need to call both methods before calling the Cllocationmanager update address. You also need to add additional nslocationalwaysusagedescription and nslocationwheninuseusaged in the Info.plist file. Escription, after doing this, I solved my problem.

According to the Apple docs:

Https://developer.apple.com/library/prerelease/ios/documentation/CoreLocation/Reference/CLLocationManager_ Class/index.html#//apple_ref/occ/instm/cllocationmanager/requestwheninuseauthorization

As of IOS 8, the presence of a NSLocationWhenInUseUsageDescription or a NSLocationAlwaysUsageDescription key value in your app's Info.plist file is required. It's then also necessary to request permission from the user prior to registering for location updates, either by calling [self.myLocationManager requestWhenInUseAuthorization]or [self.myLocationManager requestAlwaysAuthorization] depending on your need. The string entered into the Info.plist would then be displayed in the ensuing dialog.

If the user grants permission, it ' s business as usual. If They deny permission, then the delegate was not informed for location updates.

According to Apple's official documentation:

Https://developer.apple.com/library/prerelease/ios/documentation/CoreLocation/Reference/CLLocationManager_ Class/index.html#//apple_ref/occ/instm/cllocationmanager/requestwheninuseauthorization

On iOS8, you need to add a new key value nslocationwheninuseusagedescription or nslocationalwaysusagedescription in your plist file. Then, Each time you locate, you need to obtain the user's authorization information, by calling [self.myLocationManager requestWhenInUseAuthorization] or [Self.mylocationmanager requestalwaysauthorization], as to which one to call, This is based on your own needs. The key value information that you add to the Plist file will be prompted in the confirmation message.

If the user allows you to locate, you can use the positioning function as usual. If they refuse, the updated location will never be executed.

Location Services in IOS8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.