Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WatchKit and UIAlertView / UIAlertController popup

Tags:

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.

like image 811
Sam B Avatar asked Mar 17 '15 16:03

Sam B


2 Answers

(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])

}
like image 86
Ramanan R R Avatar answered Sep 20 '22 04:09

Ramanan R R


i will add the swift4 result that work for me while using

WKAlertAction

watchOS 4.0

Swift 4

        let action1 = WKAlertAction.init(title: "Cancel", style:.cancel) {
            print("cancel action")
        }
        
        let action2 = WKAlertAction.init(title: "default", style:.default) {
            print("default action")
        }
        
        let action3 = WKAlertAction.init(title: "destructive", style:.destructive) {
            print("destructive action")
        }
        
        presentAlert(withTitle: "Alert Title", message: "message is here", preferredStyle:.actionSheet, actions: [action1,action2,action3])
like image 28
Amr Angry Avatar answered Sep 24 '22 04:09

Amr Angry