[英]How to Present a particular View Controller when the application Becomes active from background on IOS Swift App
我需要展示我的應用程序的主屏幕,只要它從后台變為活動狀態,以便我可以訪問用戶的當前位置。 我的應用程序僅從主屏幕訪問用戶位置,之后不會繼續更新位置。
我怎樣才能做到這一點。 任何幫助都感激不盡。
您可以使用 function 從 AppDelegate 加載主 controller 或主 controller:
func applicationDidBecomeActive(_ application: UIApplication) {}
在 applicationDidBecomeActive 中實現以下代碼
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let yourVCToPresent = "MainScreenController" //change name as per storyboard ID
let rootViewController = storyBoard.instantiateViewController(withIdentifier: yourVCToPresent) as UIViewController
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()
這會將您的 Main controller 設置為 root 並在應用程序激活時顯示它。
此外,看看位置服務如何在適當的用戶權限下工作並相應地實施。 定位服務指南
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.