I'm looking to push a notification to the Apple Watch at a specific time. I was able to display a static message on the simulator using an apns file, but I'd like to set the data and time of the notification in the controller.
I heard I might not be able to do this on a simulator, but if I got a real phone and watch, how would it work?
So, you want to do something in the watch app extension and based on the results, schedule a UILocalNotification that will be sent to the phone at some point?
You cannot directly schedule a UILocalNotification from the watch because you don't have access to the UIApplication object. See Apple staff comment here. However, using Watch Connectivity, you could send a message from the watch to the phone and have the phone app create and schedule it in the background. The watch will display the notification iff the phone is locked at the trigger time. The watch's notification scene will be invoked in that case.
Assuming you want to send the notification from the phone to the watch: You can use UILocalNotification to send a notification to the watch - but the watch must be locked to receive it. There's also no guarantee when the Watch OS will turn on the watch to run the code that receives your notification, so your notification may arrive minutes or hours after it's sent.
Related
I would like to know that whether we can receive scheduled local notification from iphone device and we can receive that notification on Apple watch. I also want to update the status in my local database from that notification.
Note:
The app is local, it's not remote and have local database in which we have to update the status of that notification.
Thanks in advance.
Check following table from Apple and
Link
It is not possible at the moment. Unfortunately, the only way to receive notifications on Apple Watch at the moment is to have the iPhone locked.
Display my push notification message is "Message from: +919687335565"
attached screenshot :
I just want to fetch the name of this +919687335565 contact number from the Address book and display name of this contact instead of a phone number in push notification.
Before displaying notification i want to replace phone number +919687335565 with its contact name Chandresh in push notification.
like attached screenshot :
There are various possibilities for preprocessing and modify the payload of a notification on iOS.
Before iOS 10
You could be sending Silent Notifications, what will not be not shown to the user. Will wake our application when it is terminated or in background, and you will be able to do preprocessing on the notification content. See more info here, how to set it up. However, this notification type is not 100% reliable, and should not be abused, e.g. used for all notifications to be delivered, because Apple could stop the notifications to be sent after a number of messages.
The other option is, if your application supports VoIP. This way your app will pretty much always listen to push notifications, and you will be always available to preprocess the notifications, before you would be displaying them. However, if your app does not have real VoIP capabilities, e.g. phone calls, your app will be rejected by Apple on the review. Here is a great tutorial, how to set it up.
From iOS 10
With the introduction of iOS 10, we are finally able to do preprocessing on our notifications, even, when the app is in background or terminated. No VoIP capabilities or special type of notifications needed to be sent. Here is a great tutorial, how to set it up.
This is possible, except:
want to fetch name of this +91********* contact number from Address book
because Address Book is not accessible when app is in background!
You have to write separate logic in app itself to replace mobile no by appropriate name.
How other than this is possible:
Before iOS 10 and iOS 8+:
Use PushKit to send silent push notifications, app will be woken up by iOS, change the mobile no by name, show local notification.
iOS 10+:
Use Notification Service Extension to alter notification content before it'll shown to user.
Look at this official documentation
Using this service extension, iOS gives you a way to first receive notification directly to app, modify content and then deliver to user.
Here you can change mobile no by name.
No this is not possible.
Because the push notification is handle by server.
This message is only change by server not from app because that time
app is in background or terminated.
But you can change message when app is in foreground and background fetch is
enable then you can customize your message and can show it.
I am trying to write a notification tracking system for my app. My understanding is that a scheduled local notification is guaranteed to get delivered but that my app won't get a notice that it was delivered unless the user interacts with that notification in some way. Am I missing something? Is there some event or notification sent to the app simply to indicate that the notification appeared?
No, I don't think you have any way of knowing about the "notification not taken."
A Jailbroken device would be a different matter.
There are silent push notifications, and I haven't looked at the new notifications API in iOS 10, so I guess it's possible Apple added a silent local notification for iOS 10...
Actually there are 2 scenarios:
App in background: When a local notification is delivered by the system, app is not notified, only if user interacts with notification view app is awakened.
App in foreground: App is notified when a local notification is delivered by calling didReceiveLocalNotification method.
Local notifications are guaranteed to be delivered only is user allows this (app will ask user to allow to receive local notifications)
I see this in the Apple Watch Programming Guide:
When one of your app’s local or remote notifications arrives on the
user’s iPhone, iOS decides whether to display that notification on the
iPhone or on the Apple Watch.
Is there a way to make a notification only appear on the watch?
This was not possible until watchOS 3.
watchOS 3 introduces the User Notifications framework, which supports the delivery and handling of local and remote notifications. You can use the classes of this framework to schedule the delivery of local notifications based on specific conditions, such as a date or time or after a time interval, and to receive and handle local and remote notifications when they are delivered to the user’s device.
You can now schedule a local notification on the watch, and the notification is (delivered to and) only handled by the watch. It will not appear on the phone.
For more information, see the WWDC 2016 Introduction to Notifications, and Quick Interaction Techniques for watchOS sessions.
Useful picture from this guide:
Unfortunately no, with watch apps you now need to handle notifications in 3 places. When the app is running, application:didReceiveLocalNotification: is called. When the phone is unlocked the notification is sent to the notification center and you'll need to handle the user selecting it in application:didFinishLaunchingWithOptions:. The watch will automatically handle any notification its containing app gets, displaying the app and the alert's body. If you want a custom notification you'll need to setup a notification category in the containing app and a dynamic notification in the watch. If you're trying to just get information from the app to the watch you can use the app groups dictionary or the openParentApplication:reply: method.
Nope. It's completely controlled by the OS.
Whatever you can do on the watch app, you can check it from this relatively simple documentation:https://developer.apple.com/library/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/
And I don't think you can do something like what you say. We have to admit that there are a lots limitations in this version of WatchKit.
I have a VoIP app, where the incoming call notification is very important.
The problem is, sometimes I don't get the push notification (even Apple said it's not guaranteed). But, I do have a mechanism to notice that an call is coming while the app is in the background.
So, what I want to do is.. still use Push Notification as the main handler for incoming call (because it handles the situation when app is closed). However, if the push notification failed to deliver and my app gets the call invite, I will raise a local notification, telling user that you have an incoming call.
My question is... how can I check if a notification is showing before I decide whether to fire a local notification?
AFAIK you can only detect the notification when the user taps on the banner OR if the app is open when the notification comes. So I can't see a way to detect if the notification has come yet or not. Just adding to the pain, push notification is famous for its unreliability.
There’s no API to get any information about the state of your notifications. Since you’re making a VoIP app, you have the option to have it get woken up for incoming data, which would let you post your “incoming call” notification whenever you need it—see the “Configuring Sockets for VoIP Usage” section here.