首页 > 解决方案 > IOS 应用程序知道应用程序何时被锁定或使用另一个应用程序

问题描述

试图用我的应用程序弄清楚如何让应用程序知道手机何时被锁定或应用程序何时最小化并使用另一个应用程序。

这是我到目前为止所拥有的:

//warning notification
func warningNotification() {
    let content = UNMutableNotificationContent()
    content.title = "Go back to app immediately to prevent"
    //        content.body = publictime
    //        print("Notification timer\(content.body)")
    content.badge = 1

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,
                                                    repeats: false)

    let requestIdentifier = "demoNotification"
    let request = UNNotificationRequest(identifier: requestIdentifier,
                                        content: content, trigger: trigger)

    UNUserNotificationCenter.current().add(request,
                                           withCompletionHandler: { (error) in
                                            // Handle error
    })

}

标签: iosswiftxcode

解决方案


看看你的AppDelegate. 在您的情况下,您可能对applicationWillResignActiveapplicationDidEnterBackground或感兴趣applicationWillTerminate


推荐阅读