gpt4 book ai didi

ios - 是否可以区分锁定设备和将应用程序发送到 iOS 10 和 swift 的后台?

转载 作者:可可西里 更新时间:2023-11-01 01:21:32 26 4
gpt4 key购买 nike

found answer对于我的问题的 iOS 5,但是 iOS10 呢?可以在 Swift3 上实现吗?对于 iOS 5:

// Pressing the home button
Will resign active.
Did enter background.
// Tapping app icon on Springboard
Will enter foreground.
Did become active.

// Pressing the lock button
Will resign active.
Did enter background.
// Unlocking the device
Will enter foreground.
Did become active.

最佳答案

是的,当屏幕锁定时,名为 com.apple.springboard.lockcomplete 的通知会被调用。

    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
nil, { (_, observer, name, _, _) in
print("Locked")
},
"com.apple.springboard.lockcomplete" as CFString!,
nil, deliverImmediately)

要检测背景/前景模式,您需要收听通知。

 NotificationCenter.default.addObserver(self, selector:#selector(handleForegroundMode), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
NotificationCenter.default.addObserver(self, selector:#selector(handleBackgroundMode), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)

关于ios - 是否可以区分锁定设备和将应用程序发送到 iOS 10 和 swift 的后台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com