Sam B
Sam B

Reputation: 27618

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.

Upvotes: 19

Views: 12904

Answers (7)

Ramanan R R
Ramanan R R

Reputation: 906

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

}

Upvotes: 58

Amr Angry
Amr Angry

Reputation: 3851

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

Upvotes: 12

marcomoreira92
marcomoreira92

Reputation: 379

   let h0 = { print("h0 action")}
   let h1 = { print("h1 action")}

   let action1 = WKAlertAction(title: "h0 action", style: .default, handler:h0)
   let action2 = WKAlertAction(title: "h1 action", style: .default, handler:h0)

   self.presentAlert(withTitle: "Title", message: "a message", preferredStyle: .actionSheet, actions: [action1, action2])

Code in Swift 3

Upvotes: 3

Manish Gumbal
Manish Gumbal

Reputation: 293

Yes, after upgrading to watchOS 2, you can present an alert view using presentAlertController of WKInterfaceController.

See the official documentation here.

Upvotes: 3

bgilham
bgilham

Reputation: 5949

If I could make one more suggestion: Create a separate group for your "alert" in your initial interface controller and show/hide it as needed.

Upvotes: 1

Ashraf Tawfeeq
Ashraf Tawfeeq

Reputation: 3029

Sadly, you can not do this. But you can of course have a modal page-based hierarchy with screenshots of how the app is working if it is the first time that the app is launched. I am doing so in my app! :)

Upvotes: 2

gagarwal
gagarwal

Reputation: 4244

There is no such class for alerts. However you can modally present "WKInterfaceController" with the information in "WKInterfaceLabel" and one "WKInterfaceButton".

Upvotes: 2

Related Questions