0

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!

Awalias
  • 2,027
  • 6
  • 31
  • 51

1 Answers1

0

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];
    });
Adnan Aftab
  • 14,377
  • 4
  • 45
  • 54