老项目的#iPhone6与iPhone6Plus适配#iOS8没法开启定位问题和#解决方案#

本文永久地址为 http://www.cnblogs.com/ChenYilong/p/4020359.html,转载请注明出处。
iOS8的定位和推送的访问都发生了变化,

下面是iOS7和iOS8申请定位权限时的不一样:php


iOS7:

 
本文永久地址为  http://www.cnblogs.com/ChenYilong/p/4020359.html,转载请注明出处。
 

iOS8:

 
 
 
 
本文永久地址为  http://www.cnblogs.com/ChenYilong/p/4020359.html,转载请注明出处。
 
或者在真机上这样:
 
 
本文永久地址为  http://www.cnblogs.com/ChenYilong/p/4020359.html,转载请注明出处。
咱们知道苹果在iOS8上对定位进行了大幅度优化,能够支持室内定位,常去地点统计,楼层等。可是 在iOS8上currentLocation是空的,致使定位失败了。
高德也定位失败( 缘由多是未对iOS8作适配 ),或者不会调用到定位以后的delegate方法中,而后我查看了一下手机上对应用的定位权限界面,发现个人应用的访问用户的地理位置的权限是空的,以后查了相关信息,获得如下解决方案:

iOS新增了下面的方法:
 
⓵requestWhenInUseAuthorization
⓶requestAlwaysAuthorization
用法

1.在AppDelegate中或者其它设置CLLocationManager的控制器中


声明
@property ( nonatomic , strong ) CLLocationManager *locationManager;

实现中添加以下代码
   [ UIApplication sharedApplication ]. idleTimerDisabled  TRUE ;
   
self . locationManager  = [[ CLLocationManager  alloc ] init ];
   
self . locationManager . delegate  self ;
   self.locationManager.desiredAccuracy kCLLocationAccuracyBest;
    if ( IS_IOS8 ){

[    self . locationManager  requestAlwaysAuthorization ];
    //NSLocationAlwaysUsageDescription
    [
self . locationManager  requestWhenInUseAuthorization ];
   //NSLocationWhenInUseUsageDescription
}
    [self.locationManager startUpdatingLocation];

或者这样:html

 

if([CLLocationManager locationServicesEnabled])ios

{web

    self.locationManage = [[[CLLocationManager alloc] init] autorelease];api

    self.locationManage.delegate = self;微信

    self.locationManage.distanceFilter = 200;app

    self.locationManage.desiredAccuracy = kCLLocationAccuracyBestForNavigation;post

    //kCLLocationAccuracyBest;优化

    if (SYSTEM_VERSION >= 8.0) {ui

        //使用期间

        [self.locationManage requestWhenInUseAuthorization];

        //始终

        //or

        [self.locationManage requestAlwaysAuthorization]

    }

}

另外也提供下新增下面的代理方法:

 

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status

{

    switch (status) {

        case kCLAuthorizationStatusNotDetermined:

            if ([self.locationManage respondsToSelector:@selector(requestAlwaysAuthorization)])

            {

                [self.locationManage requestWhenInUseAuthorization];

            }

            break;

        default:

            break;

    }

    

}

详情见 https://app.yinxiang.com/l/ABarZZCJ2_dAd7B0ncWryoyV2bZ06fI1_WM
 

AppDelegate是这样设置的:

 

@interface AppDelegate()<CLLocationManagerDelegate>

{

    UINavigationController *_navController;

    CLLocationManager      *_locationmanager;

}

 

@end

 

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    [UIApplicationsharedApplication].idleTimerDisabled = TRUE;

    

    _locationmanager = [[CLLocationManager alloc] init];

    [_locationmanager requestAlwaysAuthorization];        //NSLocationAlwaysUsageDescription

    [_locationmanager requestWhenInUseAuthorization];     //NSLocationWhenInUseUsageDescription

    _locationmanager.delegate = self;

//....

}

本文永久地址为  http://www.cnblogs.com/ChenYilong/p/4020359.html,转载请注明出处。


2. 须要plist文件中进行设置:
设置方法:
 在 info.plist里加入:
    NSLocationWhenInUseUsageDescription,容许在前台获取GPS的描述
    (网上广为流传的NSLocationWhenInUseDescription,是不正确的,亲测不可行.请参照官方文档,连接已在文章结尾处给出.)
    NSLocationAlwaysUsageDescription,容许在后台获取GPS的描述
  以下图:

具体的文字提示,能够参照微信
你将获得这样的效果:
 
 
 
 
也能够这样设置:
 
你将获得这样的效果:
 
 
‘友情提示:若是你的应用开启了在后台运行GPS,必须在App的iTunes介绍里,加一句 "Continued use of GPS running in the background can dramatically decrease battery life.”,不然苹果会把你的App拒掉….亲测是的….

Reasons:

  • 2.16: Multitasking Apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc. 

Hello,

We found the following rejection while reviewing your app. Please see more details below.

We found that your app uses a background mode but does not include the following battery use disclaimer in your Application Description:

"Continued use of GPS running in the background can dramatically decrease battery life."

It would be appropriate to revise your Application Description to include this disclaimer.

If your iTunes Connect Application State is Metadata Rejected, we do NOT require a new binary. 

To revise the metadata:

- Log in to iTunes Connect
- Click on “My Apps”
- Select your app
- Revise the desired metadata values 
- Click “Save" 
- Once you’ve completed all changes, click the “Submit for Review” button at the top of the App Details page

Kind Regards,

The App Review Team

 
 
 
你模仿高德地图等应用,这样写:
【舒适提示】
本App的主要服务会持续使用GPS定位服务,切换至后时,仍会继续,相比其余操做会消耗更多的电量,并影响电池续航时间。
使用位置共享过程当中,您能够随时退出,停止位置共享。本App不会将您的真实位置暴漏或提供给第三方。
Continued use of GPS running in the background can dramatically decrease battery life.

添加以上内容以后便可以进行定位服务,下面的一些问题#解决方案#也是如此:
  1. iOS8 高德地图SDK MAMapView没法定位的问题(http://blog.csdn.net/johnzhjfly/article/details/39497751)
  2. iOS8 百度地图SDK MAMapView没法定位的问题
  3. iOS8 Location not accessible
  4. iOS8 MKMapView 代理无效问题
  5. Access the user's location on Today Extension 
  1. iOS8没法开启定位问题
本文永久地址为  http://www.cnblogs.com/ChenYilong/p/4020359.html,转载请注明出处。
 
 
扩展阅读:
  1. iOS8 定位新增功能(http://blog.csdn.net/yongyinmg/article/details/39521523)
  2.  
 
 
另外这是iOS8申请push权限也变了,其api也变了
 
请注意,在此不作赘述.
 
 
本文永久地址为  http://www.cnblogs.com/ChenYilong/p/4020359.html,转载请注明出处。

https://developer.apple.com/library/IOs/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html

相关文章
相关标签/搜索