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

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


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;

实现中添加如下代码
   [UIApplicationsharedApplication].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];

或者这样:

 

if([CLLocationManager locationServicesEnabled])

{

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

    self.locationManage.delegate = self;

    ;

    self.locationManage.desiredAccuracy = kCLLocationAccuracyBestForNavigation;

    //kCLLocationAccuracyBest;

    if (SYSTEM_VERSION >= 8.0) {

        //使用期间

        [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