今天扩展UIAlertController功能不可用

时间:2016-02-18 10:56:10

标签: ios objective-c ios8-today-widget

我正在进行今天的扩展,我试图让它像这样显示一个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调用此代码。 谁能告诉我为什么这段代码不起作用?

2 个答案:

答案 0 :(得分:2)

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

如果您打算显示类似于警报或弹出窗口,请使用类似于警报的UI / UX创建自定义视图,并在需要时显示/隐藏。

答案 1 :(得分:1)

错误消息告诉您需要知道的一切。

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

Apple显然不允许人们提供来自今天扩展的警报,即使他们这样做我也无法想象它的存在和愉快的用户体验。