2011-11-16 27 views
0

我想要显示消息,询问用户是否接受应用程序将在其设备中使用位置服务。我怎样才能实现,没有保存他的位置?我试过做startLocationUpdates,然后stopLocationUpdates,但那不行。如果我删除了stopLocationUpdates,那是有效的,但位置指示器仍保留在状态栏中。使应用程序消息的位置授权在应用程序第一次启动时出现

如果你问我为什么需要这个,我在稍后的几个屏幕上使用Core Location方法。在使用它们之前,我会检查+ (CLAuthorizationStatus)authorizationStatus,如果它与“授权”不同,我会给出警告消息。那是错的吗?

谢谢!

回答

0

我想你打电话给startLocationUpdates然后stopLocationUpdates在同样的方法?

如果是这样,则情况下尝试以下方法:

// Assuming that you have a property called locationManager 
// If you don't then you should at least have an initiated member 
// in order to succeed with the second line below 
[self.locationManager startUpdatingLocation]; 
[self.locationManager performSelector:@selector(stopUpdatingLocation) withObject:nil afterDelay:0.1]; 

这样的stopLocationUpdates方法将在未来runloop被调用。

+0

谢谢,这工作!我只是不得不将延迟更改为0.2,因为有时它有效,有时不会。 – ozking

+0

嘿,它会被苹果批准吗? 来自苹果指南的引用: “4.1在收集,传输或使用位置数据之前未通知并获得用户同意的应用程序将被拒绝” – ozking

+0

该应用程序将自动提示用户从操作系统获取使用位置的权限。你应该没问题。 –

相关问题