- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试在我的 iOS 应用程序中获取用户位置。我首先在我的项目中包含了 corelocation 框架。然后点击一个按钮,我正在调用核心位置 api,如下所示。当我尝试在设备中安装它时,核心位置从不询问用户许可。当我尝试在单击按钮时获取位置时,我得到 kCLAuthorizationStatusNotDetermined 作为授权状态。请帮助我。我不知道发生了什么。
- (IBAction)fetchLessAccurateLocation:(id)sender {
[self.txtLocation setText:@""];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 1000;
if ([self shouldFetchUserLocation]) {
[locationManager startUpdatingLocation];
}
}
这是我的 shouldFetchUserLocation 方法:
-(BOOL)shouldFetchUserLocation{
BOOL shouldFetchLocation= NO;
if ([CLLocationManager locationServicesEnabled]) {
switch ([CLLocationManager authorizationStatus]) {
case kCLAuthorizationStatusAuthorized:
shouldFetchLocation= YES;
break;
case kCLAuthorizationStatusDenied:
{
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"App level settings has been denied" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
alert= nil;
}
break;
case kCLAuthorizationStatusNotDetermined:
{
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"The user is yet to provide the permission" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
alert= nil;
}
break;
case kCLAuthorizationStatusRestricted:
{
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"The app is recstricted from using location services." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
alert= nil;
}
break;
default:
break;
}
}
else{
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"The location services seems to be disabled from the settings." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
alert= nil;
}
return shouldFetchLocation;
}
这是我的核心位置委托(delegate)方法:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0){
NSLog(@"location fetched in delegate");
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// If the event is recent, do something with it.
NSLog(@"inside loop.... latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
}
NSLog(@"latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
[self.txtLocation setText:[NSString stringWithFormat:@"\nlatitude: %+.6f \nlongitude: %+.6f", location.coordinate.latitude, location.coordinate.longitude]];
[locationManager stopUpdatingLocation];
[locationManager stopMonitoringSignificantLocationChanges];
if(locationManager!=nil){
locationManager.delegate= nil;
locationManager= nil;
}
}
最佳答案
假设[CLLocationManager locationServicesEnabled]
返回 YES,
首次启动 iOS 应用程序 [iOS7 和 iOS8] - locationMangers(CLLocationManager) authorizationStatus预设为
authorizationStatus(CLAuthorizationStatus) = kCLAuthorizationStatusNotDetermined
启动位置管理器(CLLocationManager, Strong) 并设置委托(delegate)(CLLocationManagerDelegate)
现在提示用户使用位置服务并在设置> 隐私> 位置服务下列出应用程序,它必须调用任何位置服务方法,这取决于应用程序要求 - 例如,如果应用程序是一种以下的
位置更新 - [self.locationManager startUpdatingLocation]
RegionMonitoring - [self.locationManager startMonitoringForRegion:beaconRegion]
执行上述方法后,iOS 将立即提示用户请求接受在应用程序中使用位置服务,并且无论用户选择如何,应用程序都将列在“设置”>“隐私”>“位置服务”下。
iOS8也是一样,首先推出了App Locations Services
authorizationStatus(CLAuthorizationStatus) = kCLAuthorizationStatusNotDetermined
iOS 8 我们获得了向用户显示提示的新方法
[self.locationManager requestAlwaysAuthorization]
or
[self.locationManager requestWhenInUseAuthorization]
requestAlwaysAuthorization/requestWhenInUseAuthorization 可从 iOS8 获得。如果应用程序部署目标是 iOS7,则将其包装在 if block 下,以确保在 iOS7 中这不会导致应用程序崩溃。
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[self.locationManager requestAlwaysAuthorization]; .
}
或
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
}
根据 iOS8,它必须包含说明应用为何使用 requestAlwaysAuthorization/requestWhenInUseAuthorization 的字符串在 info.plist 中包含与应用程序要求相关的任何这些属性
对于 kCLAuthorizationStatusAuthorizedAlways 包含键/值(字符串值)对
NSLocationAlwaysUsageDescription = App use Locations service mode Always
对于 kCLAuthorizationStatusAuthorizedWhenInUse 包括键/值(字符串值)对
NSLocationWhenInUseUsageDescription = App use Locations service mode In Use
关于iOS:应用程序在安装应用程序时不征求用户的许可。每次都获取 kCLAuthorizationStatusNotDetermined - Objective-c & Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20664928/
我正在设计一款支持签到的应用。 使用应用程序时的 GPS 权限是必须。但是有一个使用地理围栏自动 checkin 的可选功能,它需要“始终”gps 权限。 我想首先请求常规的“使用时”权限。然后,仅当
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 8 年前。 Improve
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
最近,我研究了使用 OnGuard 来帮助诚实的人遵守他们的原则。我同意这里许多人表达的观点,即任何许可制度都无法保护您免受那些想要使用您的软件但不想付费的人的侵害。另一方面,我希望避免让其他人太容易
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我试图在计算机上设置Windows Developer许可证,但失败。 我正在运行Visual Studio 2012。 当我单击“项目”->“商店”->“获取开发者许可证”时,它向我显示一个信息对话
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭11 年前。 Improve th
我想购买 Delphi Xe2 Pro。我独自一人使用它,我有 2 台电脑:一台在办公室,一台可移植用于“在路上”工作。Delphi Xe2 许可证不是很清楚,因此有什么办法可以为 2 台 PC 只购
我正在我的应用程序中安装 Android Licensing,我想知道什么是检查许可证的良好形式 - 每次或仅一次并保存它已被许可共享偏好的事实?我担心的是,如果用户处于离线状态,他们将被锁定在应用程
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
有人知道 WinRT 应用程序的许可是如何工作的吗? 我已向 Microsoft 申请了免费的开发人员许可证,这似乎与 temporarykey.pfx 或 appxmanifest 文件相关联。问题
我一直在网上搜索如何接受 Xcode,以便使用 Xcode 为 MAC 重新编译 MATLAB Windows 文件,但我没有找到任何相关的答案。 我在 MATLAB 中得到的错误消息是: Xcode
一些工作推到 QA,一些工作推到生产。 应该只允许开发人员推送到 QA,并且只允许 QA 推送到生产。除了制作两个单独的构建服务器(通过某种方式共享工件)之外,我如何限制权限? 最佳答案 您需要基于项
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
在 MacOS Catalina 上升级到 Xcode 11.1 后,运行一些命令(例如 git status)会导致 Xcode 声明必须同意许可。显然,我们可以运行 git status 和 gr
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
在 MacOS Catalina 上升级到 Xcode 11.1 后,运行一些命令(例如 git status)会导致 Xcode 声明必须同意许可。显然,我们可以运行 git status 和 gr
我正在构建一个小型 winforms 应用程序:ayende rhino licensing .许可工作正常,我可以创建许可并按我的选择分发它们。 问题是,如何让每个许可证只在一台机器上工作?我知道在
我是一名优秀的程序员,十分优秀!