用户拒绝位置,我将用户发送到“设置”应用中的位置设置:
UIApplication.sharedApplication().openURL(NSURL(string:"prefs:root=LOCATION_SERVICES")!)
用户从“设置”应用中授权位置,返回到我的应用,左上角为Back to App
我怎么知道他回到了应用程序? viewDidAppear
无效
答案 0 :(得分:4)
您可以通过检查AppDelegate's
方法轻松检测: -
func applicationWillEnterForeground(application: UIApplication!) {
或者在NSNotificationCenter
的视图控制器的viewDidLoad()中注册通知: -
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillEnterForeground", name: UIApplicationWillEnterForegroundNotification, object: nil)
//calling selector method
func applicationWillEnterForeground() {
println("did enter foreground")
}
答案 1 :(得分:0)
答案 2 :(得分:0)
在viewController中使用NSNotificationCenter
在viewDidLoad
上调用此方法- (void)registerAppEnterForeground
{
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationWillEnterForeground)
name:UIApplicationWillEnterForegroundNotification
object:nil];
}
-(void)applicationWillEnterForeground
{
/*HANDLE YOUR CODE HERE*/
}