Say i have an app with interactive notfications to be displayed on the Apple Watch. Lets say its a mail app for example, with a "reply with a thumb" button. When the user clicks that, it would be desirable to display some sort of result on the notification, for example "Mail was sent" or "Unable to send, server not found".
I can't find anything in the notification api to do this, which i find unfortunate. Just wanted to check if someone has the same usecase and if i have missed some (other) way to solve this.
You can have your app respond to the options in the notifications in the WKExtensionDelegate method handleActionWithIdentifier(_:forRemoteNotification:). This can perform a network request which can in turn send another push notification, or you can schedule a local notification as a result of the network request. Check out the UILocalNotification API
Related
I am creating an iOS application and its scenario is:
A user orders something from a vendor. When he places the order, the app asks him to wait. I want the user to know when the vendor accepts/reject the order.
Am I supposed to use push notifications for this purpose or is there any other better approach?
The simple answer is yes. A push notification is the best way to update a user. The advantage of using a push notification is that the user no longer has to be in the app to receive this update. However if they are still in the app you can handle the content in the push notification payload. For example you could show a success message or failure message.
We have iOS push notifications configured and running. However, we would like the user to select which categories are interesting to receive and which are not important and would like to omit receiving those notifications.
Is there any way to do this through Apple push notification itself rather than through the server sending the notifications? (We can change the sent JSON). Can the iPhone send which categories it would like to receive and which are not needed by registering them to Apple? Other choice, can we interrupt the push notification before being shown and decide whether it should be shown or not through a delegate? So far, I can't find an available method to do either.
Any help is appreciated
The short answer is not from the client side. If you want a solution that works 100% of the time you will need to do something on a server which only sends the types of push notifications the user subscribes to.
If your App is in background there is no concept of "categories" of PUSH notifications and you have no control over if they show up in the notification center.
You can examine inbound push when the App is in the foreground and decide on the basis of some meta data to display or not, but that is not a 100% solution.
How can I send a text message (natively or through the use of an API) from an iOS application to someone without having them have to interact with the message before hand?
The message would be prewritten and would send on tap of screen. Its ok if the user needs to okay it once, but I need a way to send a message without having to have the user interact with their device each time.
Example:
Phone is off, I shake phone, phone senses shake, sends text messaging saying "I'm shaking" to another user via SMS or MMS without having the user need to OK the sending. Is this possible? How would I do it?
You can't do that. You need to show the user the message in the MFMessageComposeViewController that pops up first, and he has to send it by himself.
This restriction was made, because otherwise, many apps could spam your contacts etc. with a massive amount of sms or they could even write sms to expensive numbers.
But if you want to send just some kind of notification to another user, you could use push notifications. To do that, I would recommend you to use parse.com and their free push notification-service. Also, because Push Notifications are free, in contrast to SMS, you will save a lot of money. Of course you need to make some preparations before you can send notifications, but that way you could do it. But also there are restrictions. One restriction is, that the receiver of the notification also must have the app installed on the receiving device.
So the receiver would receive a "message" like that:
So I would recommend you to check the QuickStart Guide from Parse.com for iOS for further informations. The Guide is really simple and shows you step by step how to activate your app for Push notifications.
Sorry, but you can't, it is completely impossible. The only way to send sms is through messageUI, which always requires the users consent. You can probably do it on a jailbroken phone, though.
Yes, it is possible. But you would have to use a 3rd party service to send the text message. for example, Twilio.
I basically want to make multiple push notifications in the same application visible in the notification tray in iOS.
This scenario works if my data is on while push notification is triggered via APNS, but only the latest one is received in case I am offline and come back after a while. This functionality is affirmed by APNS documentaion.
However, this is what worked in WhatsApp:
Turned Data Connection OFF
Sent some messages to WhatsApp
Turned Data Connection ON
Saw multiple push notifications received in Apple's Notification Tray
How's this scenario working? Can I use APNS for this? If yes, then how?
See this sample image of multiple Push Notifications in WeChat.
Like you wrote in your question, this is mentioned in the Apple Docs:
If you are sending multiple notifications to the same device or
computer within a short period of time, the push service will send
only the last one.
Link
The only scenario that what you're describing will work is if your whatsApp was open in the background while getting those push notifications. That way whatsApp will handle them as local notifications and will present all of them in the notification center. If whatsApp was closed you'd get only the last notification like any other app.
You can easily test this:
Terminate whatsApp and turn on Airplane mode.
Send your device 5 messages from 1 to 5.
Turn Airplane mode off and lock your device.
You'll only see one msg (the last one you sent aka "5") in your notifications center.
This is how whatsApp is making it work:
While whatsApp is in the background, a single push notification is received (the last one the user sent, "5" in our example). That msg will not be shown to the user.
whatsApp receives it in the method application:didReceiveRemoteNotification:fetchCompletionHandler: and checks against their servers if there are any notifications prior to "5" that the user didn't receive. If that's the case, they will pull that data from their servers and will present it to the user using local notifications which is basically just a way to present data and not related to APNS at all.
It is explained in Troubleshooting Push Notifications. Check for "Some Notifications Received, but Not All" section.
As described you cannot have any control over those push notifications.
However you may know that from iOS7 a new background execution mode (remote-notification) allows the App to be awaken by the system when a push is received, allowing you to process some data, then go back to sleep...
This is probably the trick: using that way to receive the push notifications (silently) and then trigger your own local notification instead as #Segev said. See the UIBackgroundModes here.
When the app is in foreground and it receives a notification, the alert message is shown and it only has an "OK" button, no "Cancel". So the user can't really say: "I want to ignore this message".
Yet, I do need to give users the ability to ignore the notification. They contain a deep link and the user might not want to be taken to another page if she is reading something else.
To do this I implemented a custom alert saying: "Do you want to be taken to this article? Yes / No" and only if "Yes" is chosen the user is taken to the deep link.
The problem is I don't know how to find out when the standard alert has been closed. So I show my custom alert in didReceiveRemoteNotification which results in two alerts overlapping (bad).
What is the recommended solution to give the user a chance to ignore a notification when she is already in the app? Is there a way to customise the default alert message when the app is in foreground?
When your app is in the foreground iOS does not handle the notification. It is directly delivered to your app and your app is handling the notification.
If you have two dialog them most probably your is presenting them both.
This is stated in Local and Push Notification Programming Guide
If the app is running in the foreground when the notification is delivered, the app delegate receives a local or remote notification.
As the doc said, the app delegate will handle the notification.