21 NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
22 NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
27 using NotificationMap = QMap<NSNotificationName, UIApplicationState>;
29 { NSExtensionHostWillEnterForegroundNotification, UIApplicationStateInactive },
30 { NSExtensionHostDidBecomeActiveNotification, UIApplicationStateActive },
31 { NSExtensionHostWillResignActiveNotification, UIApplicationStateInactive },
32 { NSExtensionHostDidEnterBackgroundNotification, UIApplicationStateBackground },
34 { UIApplicationWillEnterForegroundNotification, UIApplicationStateInactive },
35 { UIApplicationDidBecomeActiveNotification, UIApplicationStateActive },
36 { UIApplicationWillResignActiveNotification, UIApplicationStateInactive },
37 { UIApplicationDidEnterBackgroundNotification, UIApplicationStateBackground },
40 for (
auto i = notifications.constBegin();
i != notifications.constEnd(); ++
i) {
41 [notificationCenter addObserverForName:
i.key()
object:nil
queue:mainQueue
42 usingBlock:^
void(NSNotification *notification) {
43 NSRange nameRange = NSMakeRange(2, notification.name.length - 14);
44 QString reason = QString::fromNSString([notification.name substringWithRange:nameRange]);
52 "Extension loaded, assuming state is active"_L1);