How to show Alert on apple watch. Is there any alternate to show alerts in the Apple Watch because I checked and UIAlertView is not working on Apple Watch.
If you don't see notifications on your Apple Watch To check your connection, swipe up on the watch face to open Control Center. If your devices are disconnected, you might see the red iPhone icon , the red X icon , or the Wi-Fi icon . Try to connect your iPhone and Apple Watch.
Turn off wrist detection. If you're wearing your Apple Watch but it doesn't detect you are, switch off wrist detection to circumvent the sensor. Switch off Cover to Mute. Like the Apple Watch's Do Not Disturb mode, Cover to Mute silences notifications, including text messages.
With watchOS2
With watchOS2 you can use the WKAlertAction method:
+ (instancetype nonnull)actionWithTitle:(NSString * nonnull)title
style:(WKAlertActionStyle)style
handler:(WKAlertActionHandler nonnull)handler
With watchOS1
If you don't mind losing the feature of an UIAlertView of seeing the content behind, you can:
1 - Create an ErrorInterfaceController (with or without an ok button)
2 - Set the identifier to "ErrorInterfaceController"
3 - Present that error with:
[self presentControllerWithName:@"ErrorInterfaceController"
context:@{@"title" : @"yourTitle",
@"text" : @"yourText"}];
4 - In your ErrorInterfaceController.m you can set your title and text with the context.
Note that your ErrorInterfaceController can have a title that is empty and the ok button can dismiss it or you can leave the way it is with a default "Done".
This is the simplest solution to present a message.
If you want something more complex you need to remember that WatchKit doesn't have a z-index and you can't add elements dynamically by code. Therefore, you need to have a solution that uses UIImages rendered in your app extension and sending them to the WatchKit.
Update for Swift 3.0 - In 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])
Hope it helps !!!
For watchOS 2, here is an example:
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 ]];
In 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
}])
In watchOS 1
You should make a second interface controller, as Tiago says, then present the second one from the first one:
Objective-C
[self presentControllerWithName:@"ErrorInterfaceController"
context:@{@"title" : @"yourTitle",
@"text" : @"yourText"}];
Swift
self.presentController(name: "ErrorInterfaceController", context:["title":"yourTitle" , "text":"yourText"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With