Подтвердить что ты не робот

Как показать оповещение на Apple Watch

Как показать оповещение на часах яблока. Есть ли альтернатива, чтобы показывать предупреждения в Apple Watch, потому что я проверил, и UIAlertView не работает на Apple Watch.

4b9b3361

Ответ 1

С watchOS2

С помощью watchOS2 вы можете использовать метод WKAlertAction:

+ (instancetype nonnull)actionWithTitle:(NSString * nonnull)title
                                 style:(WKAlertActionStyle)style
                               handler:(WKAlertActionHandler nonnull)handler

С watchOS1

Если вы не возражаете потерять функцию UIAlertView для просмотра содержимого позади, вы можете:

1 - Создайте ErrorInterfaceController (с кнопкой или без кнопки ok)

enter image description here

2 - Установите идентификатор в "ErrorInterfaceController"

enter image description here

3 - Представьте эту ошибку с помощью:

[self presentControllerWithName:@"ErrorInterfaceController" 
                        context:@{@"title" : @"yourTitle",
                                  @"text"  : @"yourText"}];

4 - В вашем ErrorInterfaceController.m вы можете указать свой заголовок и текст в контексте.

Обратите внимание, что ваш ErrorInterfaceController может иметь заголовок, который пуст, и кнопка ok может отменить его, или вы можете оставить способ по умолчанию "Готово".

Это простейшее решение для представления сообщения.

Если вам нужно что-то более сложное, вам нужно помнить, что у WatchKit нет индекса z, и вы не можете динамически добавлять элементы по коду. Поэтому вам нужно иметь решение, которое использует UIImages, отображаемое в вашем приложении, и отправляет их в WatchKit.

Ответ 2

Для watchOS 2, вот пример:

WKAlertAction *action =
            [WKAlertAction actionWithTitle:@"OK"
                                     style:WKAlertActionStyleDefault

                                   handler:^{
                                       // do something after OK is clicked
                                   }];

NSString *title = @"Oops!";
NSString *message = @"Here comes the error message";

[self.interfaceController
            presentAlertControllerWithTitle:title
                                    message:message
                             preferredStyle:WKAlertControllerStyleAlert
                                    actions:@[ action ]];

Ответ 3

В watchOS 2

Objective-C

NSString *titleOfAlert = @"Something Happened Wrong";
NSString *messageOfAlert = @"Error Message Here";
[self.interfaceController presentAlertControllerWithTitle: titleOfAlert
                                                  message: messageOfAlert
                                           preferredStyle:
                                            WKAlertControllerStyleAlert
                                           actions:@[
                                              [WKAlertAction actionWithTitle: @"OK"
                                                             style: WKAlertActionStyleDefault
                                                             handler: ^{
                                                                //something after clicking OK
                                                             }
                                           ]];

Swift

let titleOfAlert = "Something Happened Wrong"
let messageOfAlert = "Error Message Here"
self.interfaceController.presentAlertControllerWithTitle(titleOfAlert, message: messageOfAlert, preferredStyle: .Alert, actions: [WKAlertAction(title: "OK", style: .Default){
    //something after clicking OK
}])

В watchOS 1

Вы должны сделать второй контроллер интерфейса, как говорит Тьяго, затем представить второй из первого:

Objective-C

[self presentControllerWithName:@"ErrorInterfaceController" 
                    context:@{@"title" : @"yourTitle",
                              @"text"  : @"yourText"}];

Swift

self.presentController(name: "ErrorInterfaceController", context:["title":"yourTitle" , "text":"yourText"])

Ответ 4

Еще один вариант - разместить свой опознавательный интерфейс в группе и показать/скрыть его по мере необходимости. В зависимости от вашего дизайна приложения это может работать неплохо. Я делаю что-то подобное для показа пользовательского интерфейса загрузки.

Ответ 5

Обновление для Swift 3.0 - В watchOS 3.0

let action = WKAlertAction(title: "Decline", style: WKAlertActionStyle.default) {
        print("Ok")
    }
    presentAlert(withTitle: "Message", message: "Please select value. Swipe right to change it.", preferredStyle: WKAlertControllerStyle.alert, actions:[action])

Надеюсь, это поможет!!!