【问题标题】:How to Show Network not Available Message tvOS如何显示网络不可用消息 tvOS
【发布时间】:2016-05-17 02:59:08
【问题描述】:

我正在使用为 tvOS 开发的 client/server 模型,应用程序在该模型中获取远程 javascript 文件来描述视图。

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

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

干杯!

【问题讨论】:

    标签: tvos apple-tv tvos9.1


    【解决方案1】:

    要显示警报,您至少需要一个带有 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];
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 2017-12-08
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 2015-05-13
      相关资源
      最近更新 更多