首页 > 解决方案 > iOS12+的Objective-C版serviceSubscriberCellularProvidersDidUpdateNotifier?

问题描述

有这个链接,但是它忽略了 iOS 12+ Objective C 方法。这是我尝试过的:

添加到应用程序委托:

@property (strong, nonatomic) CTTelephonyNetworkInfo *telephonyInfo;

然后在

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...

    self.telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];

    self.telephonyInfo.serviceSubscriberCellularProvidersDidUpdateNotifier = ^(NSString *entry) {
        dispatch_async(dispatch_get_main_queue(), ^{
            qDebug() << "User did change SIM" << entry;
        });
    };
    ...
}

但是当我移除 SIM 卡时,代码永远不会被执行(通过断点或日志消息)。如何在 iOS 12+ 的 Obj-C 中获取通知?

标签: iosobjective-ccore-telephony

解决方案


推荐阅读