0

我正在使用为 tvOS 开发的客户端/服务器模型,其中应用程序获取远程 javascript 文件来描述视图。

但是如果网络不可用(我使用Nanayakkara 的 Reach对此进行测试),我该如何显示警报?

我目前在设备上拥有的唯一文件是 AppDelegate.swift(还没有故事板/视图控制器等,但我真的需要这些来显示警报吗?)

干杯!

4

1 回答 1

0

要显示警报,您至少需要一个带有 rootViewController 的窗口,因此您可以显示 alertController,以下是您为此目的所需的最少代码

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    _alert= [UIAlertController alertControllerWithTitle:@"Alert" message:@"Message here" preferredStyle:UIAlertControllerStyleAlert];
    _window.rootViewController = [UIViewController new];

    [_window makeKeyAndVisible];
    dispatch_async(dispatch_get_main_queue(), ^{
        [_window.rootViewController presentViewController:_alert animated:YES completion:nil];
    });
于 2016-02-07T16:08:00.797 回答