老項目的#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

相關文章
相關標籤/搜索