今天扩展 UIAlertController 功能不可用

Today extension UIAlertController feature not available

我正在做今天的扩展,我试图让它像这样显示一个 AlertController:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertView" message:@"I am an AlertView" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction * action) {
                                                          [alert dismissViewControllerAnimated:YES completion:nil];
                                                      }];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];

遗憾的是,它在第​​一行崩溃并出现以下错误:

2016-02-18 11:53:46.311 App Scenes[17870:669107] *** Assertion failure in void _UIApplicationAssertForExtensionType(NSArray *__strong)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.30.14/UIApplication.m:2446
2016-02-18 11:53:51.230 App Scenes[17870:669107] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Feature not available in extensions of type com.apple.widget-extension'

我从 TodayViewController 调用这段代码。 谁能告诉我为什么这段代码不起作用?

错误信息告诉你所有你需要知道的。

reason: 'Feature not available in extensions of type com.apple.widget-extension'

Apple 显然不允许人们显示来自今天扩展的警报,即使他们这样做了,我也无法想象它是一种愉快的用户体验。

iOS 扩展不支持 UIAlertViewController 或以任何方式显示警报。

如果您打算显示类似于警报或弹出窗口的内容,请创建一个自定义视图,其中 UI/UX 类似于警报,并且 show/hide 在任何需要的地方。