WatchKit和UIAlertView/UIAlertController弹出窗口

Sam*_*m B 19 ios watchkit

在我的WatchKit应用程序中,当用户首次启动它时,我想向他们提供一个有用的消息提醒,告诉他们应用程序的工作方式,例如按钮的功能等.

是否有类似于UIAlertView/UIAlertController的东西我可以在WatchKit应用程序中调用?我无法找到关于这个主题的答案,这很可能意味着它不可能.

Ram*_*R R 56

(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];
Run Code Online (Sandbox Code Playgroud)

迅速

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

}
Run Code Online (Sandbox Code Playgroud)


Amr*_*gry 7

我将在使用时添加对我有用的swift4结果

WKAlertAction

watchOS 4.0

斯威夫特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])
Run Code Online (Sandbox Code Playgroud)