有时会显示iOS系统消息并中断应用程序。例如,隐私系统消息可能会要求访问相册或使用麦克风,或者系统消息可能会显示通知,例如电量不足。
Swift中的iOS7 / 8/9可以使用哪些技术来检测和监控系统消息或通知何时显示以及何时被解除?
答案 0 :(得分:1)
所以看起来这实际上可以通过跳板通知/达尔文通知来完成。我到目前为止仅对提醒警报进行了测试,看起来效果很好。
- (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);
}
以下是您可以收听的所有不同跳板通知的列表。可能需要将它们中的一些组合起来才能达到您想要的效果 Full List
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