资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

iOS8.0CLLocationManager定位不响应

if ([CLLocationManager locationServicesEnabled]) {
        
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
        // As of iOS 8, apps must explicitly request location services permissions. INTULocationManager supports both levels, "Always" and "When In Use".
        // INTULocationManager determines which level of permissions to request based on which description key is present in your app's Info.plist
        // If you provide values for both description keys, the more permissive "Always" level is requested.
        if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1 && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
            BOOL hasAlwaysKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil;
            BOOL hasWhenInUseKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] != nil;
            if (hasAlwaysKey) {
                [self.m_locationManager requestAlwaysAuthorization];
            } else if (hasWhenInUseKey) {
                [self.m_locationManager requestWhenInUseAuthorization];
            } else {
                // At least one of the keys NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription MUST be present in the Info.plist file to use location services on iOS 8+.
                NSAssert(hasAlwaysKey || hasWhenInUseKey, @"To use location services in iOS 8+, your Info.plist must provide a value for either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription.");
            }
        }
#endif /* __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 */
        
        [self.m_locationManager startUpdatingLocation];

上述代码添加在

成都创新互联公司长期为数千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为凉州企业提供专业的成都网站制作、做网站,凉州网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。

[self.m_locationManager startUpdatingLocation];

之前,

除了上述代码,还需要在info.plist中添加:

NSLocationWhenInUseUsageDescription

这里是授权弹出框描述文字

    

NSLocationAlwaysUsageDescription

这里是授权弹出框描述文字


本文名称:iOS8.0CLLocationManager定位不响应
文章网址:http://cdkjz.cn/article/pceedj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220