在WebView中添加定位功能

来源:互联网 发布:sql语句大全实例 编辑:程序博客网 时间:2024/05/31 19:19

1.导入头文件 #import< CoreLocation/CoreLocation.h>

2.在info.plist中设置配置
NSLocationWhenInUseDescription
NSLocationAlwaysUsageDescription

3.在webview需要定位的地方添加如下代码

@property (nonatomic, strong) CLLocationManager *locationMgr;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {

            //由于IOS8中定位的授权机制改变 需要进行手动授权              self.locationMgr = [[CLLocationManager alloc] init];              //获取授权认证              [self.locationMgr requestAlwaysAuthorization];              [self.locationMgr requestWhenInUseAuthorization];   }
0 0