How to Show Network not Available Message tvOS

110 Views Asked by At

I'm using the client/server model developing for tvOS, where the app fetches a remote javascript file to describe the view.

But if the network is not available (I test for this using Nanayakkara's Reach), how can I display an alert?

The only file I currently have on the device is AppDelegate.swift (don't yet have storyboard/view controllers etc. but do I really need these to just show an alert?)

cheers!

1

There are 1 best solutions below

0
On

To show an alert you would need a window with rootViewController at least, so you can present alertController, below is minimum code you would need for this purpose

_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];
    });