我正在尝试编写通用的presentAlert
函数,但是遇到一个问题,即我无法获得活动控制器,该控制器不能让我显示警报。我尝试使用[WKExtension sharedExtension].rootInterfaceCcontroller
,但这似乎不起作用。
有什么想法吗?
WKAlertAction *action = [
WKAlertAction
actionWithTitle:@"test"
style:WKAlertActionStyleDefault
handler:^{}
];
WKExtension *sharedExtention = [WKExtension sharedExtension];
dispatch_async(dispatch_get_main_queue(), ^ {[
sharedExtention.rootInterfaceController
presentAlertControllerWithTitle:title
message:message
preferredStyle:WKAlertControllerStyleAlert
actions:@[ action ]
];});