// 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.
答案 0 :(得分:1)
是的,您可以在屏幕被锁定时调用名为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)
答案 1 :(得分:1)
请不要观察" com.apple.springboard.lockcomplete"通知。 Apple最近改进了他们的应用扫描工具,通知是私有API的一部分,如果您仍然遵守此通知,您的应用将在提交期间被拒绝。