Search code examples
ioswatchkit

WatchKit and UIAlertView / UIAlertController popup


In my WatchKit app, when the user first launches it, I would like to present to them a helpful message alert that tells them how the app works, e.g. what the buttons do, etc.

Is there something similar to UIAlertView / UIAlertController that I can call in a WatchKit app? I couldn't find an answer on this topic which may very well mean that it's not possible.


Solution

  • (New in watchOS 2.0)

     WKAlertAction *act = [WKAlertAction actionWithTitle:@"OK" style:WKAlertActionStyleCancel handler:^(void){
            NSLog(@"ALERT YES ");
        }];
    
     NSArray *testing = @[act];
    
    [self presentAlertControllerWithTitle:@"Voila" message:@"This is Watch OS 2 !" preferredStyle:WKAlertControllerStyleAlert actions:testing];
    

    SWIFT

    func showPopup(){
    
        let h0 = { print("ok")}
    
        let action1 = WKAlertAction(title: "Approve", style: .default, handler:h0)
        let action2 = WKAlertAction(title: "Decline", style: .destructive) {}
        let action3 = WKAlertAction(title: "Cancel", style: .cancel) {}
    
        presentAlert(withTitle: "Voila", message: "", preferredStyle: .actionSheet, actions: [action1,action2,action3])
    
    }