系统消息和通知显示和解除时是否检测到监视器?
有时会显示iOS系统消息并中断应用程序。 例如,隐私系统消息可能会要求访问相册或使用麦克风,否则系统消息可能会显示电池电量不足等通知。
Swift中的iOS7 / 8/9可以使用哪些技术来检测和监视系统消息或通知何时显示以及何时解除?
所以看起来这实际上可以通过跳板通知/达尔文通知来完成。 到目前为止,我只在提醒警报中testing了这个function,而且看起来效果很好。
- (void)viewDidLoad { [super viewDidLoad]; //com.apple.springboard.showingAlertItem // Do any additional setup after loading the view, typically from a nib. [self registerforDeviceLockNotif]; } //call back static void displayStatusChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { NSString *lockState = (__bridge NSString*)name; NSLog(@"Darwin notification NAME = %@",name); if ([lockState isEqualToString:@"com.apple.springboard.showingAlertItem"]) { NSLog(@"Notification was shown"); } } -(void)registerforDeviceLockNotif { //Alert notification CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, // observer displayStatusChanged, // callback CFSTR("com.apple.springboard.showingAlertItem"), // event name NULL, // object CFNotificationSuspensionBehaviorDeliverImmediately); }
以下是您可以听取的所有不同跳板通知的列表。 它可能需要它们中的一些组合来实现你想要的。
完整列表
Name Firmware com.apple.springboard.bootedcleanly 2.0 – com.apple.springboard.fullycharged 2.0 – com.apple.springboard.pluggedin 2.0 – com.apple.springboard.lockinterrupted 2.0 – com.apple.springboard.callinterruptedapp 2.0 – com.apple.airportsettingsvisible 3.0 – com.apple.springboard.lockstate 2.0 – com.apple.springboard.lockcomplete 2.0 – com.apple.springboard.showingAlertItem 2.0 – com.apple.springboard.lowPowerAlertPresented 2.0 – com.apple.airport.userNotification 2.0 – com.apple.mobile.SubstantialTransition 2.0 – SignificantTimeChangeNotification 2.0 – com.apple.powerlog.exit 3.0 – com.apple.springboard.deviceWillShutDown 2.1 – SBSpringBoardDidLaunchNotification 2.1 – displayID-activated 2.2 – displayID-suspended 2.0 – com.apple.springboard.DeviceLockStatusChanged 2.0 – SBDidTurnOnDisplayNotification 2.1 – SBDidTurnOffDisplayNotification 2.1 – com.apple.springboard.activeCallStateChanged 3.0 – com.apple.springboard.attemptactivation 2.0 – SBFormattedPhoneNumber 2.0 – PSAirplaneModeChangedNotification 2.2 – com.apple.alarm.alarmchanged 2.0 – com.apple.alarm.alarmfired 2.0 – com.apple.SpringBoard.ReadyForRestore 2.0 – com.apple.springboard.syncingUnblocked 2.0 – kGSCapabilityChangedNotification 2.0 – com.apple.springboard.RentalsExpiredNotification 2.0 – com.apple.remotenotification.notificationdelivered 3.0 – SBRingerSilent 2.0 – SBRinger1 2.0 – com.apple.springboard.ringerstate 2.0 – com.apple.springboard.doubleheightmode 3.0 – com.apple.springboard.hasBlankedScreen 2.0 – com.apple.springboard.unambiguousOrientation 2.0 – com.apple.springboard.orientation 2.0 – com.apple.springboard.rawOrientation 2.2 – com.apple.springboard.curvedBatteryCapacity