How can I control the Apple Push Notifications I receive - iphone

I have successfully created a server that sends Apple Push Notifications, and my iphone receives them.
For example I have Notification of type A and notifications of type B,
How can I control the types of notifications I received on the iphone side? For example I only want type A and not B (Just like Facebook, I want notifications for Friend Request, but not for Walls)
Thanks

you cannot stop your device on receiving a specific type of notification unless it is done on server side. Though you can ignore a notification when app is in running state as you get the notification in didReceiveRemoteNotification and you can simply ignore it after checking it but if app is in background or it is closed then you cannot control the incoming notifications from within your app.
you can make a service on server to set preferences for notification types.
from device, user can enable/disable the push service for individual features and update the preferences on server from device.
On server, before sending the PUSH, you can check for the preferences selected by user from the table and send only those notifications which the user has opted for.

Related

How to get the device token in iOS 10 if user does not accept to receive Push Notifications?

I had my app for iOS 9 implementing application(_:didRegisterForRemoteNotificationsWithDeviceToken:) that gets invoked whether or not user accepts to receive Push Notifications, hence I get and store on the remote server the device token in both cases.
Now with iOS 10 this delegate method never gets called if user does not accept to receive Push Notifications... Is there any other way to get the device token in such a case?
You can't. If user doesn't accept notifications, you can't get any token for this.
This is the fact when user not accept to receive notification then application will not generate device token or sometime by mistake click on don't allow option, so whenever you want to need app required Push notification need to show any popup(Alert view) message there for why you need push notification access inside app then second time give some tutorial/advice/guidance for how user enable manually push notification service from iOS device Setting option.

Can I delete a push notification from a device which have receive this push notification?

I have the following problem.
I look for a capability to delete a push notification from a device (iPhone respectively Apple Watch) but this device have receive the push notification.
The use case is that a USER A send a request to all available USER Bs. A push notification is send to all these USER Bs. At the moment the push notification arrive it will shown on their Apple Watch. One of the USER Bs answer that he accept this request. After he press the button to accept the request the notification should be deleted on all the other devices.
I really do not know a capability to do this.
But I know that you can handle this problem in Android as provide a unique ID for this notification. After that you can delete the other notifications with this particular ID.
Is their maybe a same way for iOS like it is provided in Android?
This doesn't really have anything to do with WatchKit/Apple Watch.
To answer your main question: no, you can't do this as it describe. Once you fire off a notification, it's in the user's hands to decide what they want to do with it.
As an alternative, you could maintain an "inbox" with every notification in your app and use the notification to prompt the user to check it. That way you could remove a notification from the inbox on the server side of things.

How Google's Gmail app on iPhone disable notifications?

My question can seems weird, but I just realize that when I receive a push for a new mail from Gmail app and I open Gmail on a web page, the notification disappear.
Can someone explain me how this is working ?
This is related to this question, though it's not an exact duplicate.
This can be implemented with Apple Push Notifications.
Your server has to maintain for each user a list of device tokens of all the devices belonging to that user (iPhones, iPads, etc...).
When the user reads the message on one platform (whether via a web browser or via a mobile application), you can execute some API call on your server to notify it that the user read the message.
Then your server can send a follow-up push notification to all the devices belonging to that user with "badge"=0 (and without the "alert" and "sound" fields), and the notification will be cleared from the lock screen and app icon.
One possibility is that they use notifications delivered in the background (they get delivered directly to the app rather than being shown to the user), then use local notifications. Local notifications can be cancelled.
So it would go like this:
remote notification "there's a new e-mail" delivered in the background
local notification "new email"
...
you connect to the website
remote notification "user has seen new e-mail" delivered in the background
cancel local notification
I've never actually tried to do this, but I suppose that would be the way it works. I'm not aware of any (documented) way to cancel a remote notification directly.

can i implement an app that have 2 types of notification (Remote and newsstand notification)

i need to know if i can implement an app that can handle 2 types of notifications
Thanks
Both remote and local notifications enable an application to inform its users that it has something (information) for them - in a form of a notification (It could be a message, an impending calendar event, or new data on a remote server), when the application isn't running in the foreground.
When presented by the operating system, local and push notifications look and sound the same. They can display an alert message or they can badge the application icon. They can also play a sound when the alert or badge number is shown.
The difference between the two are:
Local notifications are scheduled by an application and delivered by iOS on the same device. Local notifications are available in iOS only.
Push notifications, also known as remote notifications, are sent by an application’s remote server (its provider) to Apple Push Notification service, which pushes the notification to devices on which the application is installed.
Push notifications are available in both iOS and, beginning with Mac OS X v10.7 (Lion), Mac OS X.
Going back to your question, the answer is YES.
As per discussed in the Apple documentation:
To have iOS deliver a local notification at a later time, an application creates a UILocalNotification object, assigns it a delivery date and time, specifies presentation details, and schedules it. To receive push notifications, an application must register to receive the notifications and then pass to its provider a device token it gets from the operating system.
When the operating system delivers a local notification (iOS only) or push notification (iOS or Mac OS X) and the target application is not running in the foreground, it presents the notification (alert, icon badge number, sound). If there is a notification alert and the user taps or clicks the action button (or moves the action slider), the application launches and calls a method to pass in the local-notification object or remote-notification payload. If the application is running in the foreground when the notification is delivered, the application delegate receives a local or push notification.
For further understanding, read more about Local and Push Notifications.

Is is possible for an application to handle the response from a push notification?

Is it possible to get the user's response from a push notification and create a notification reply? i.e. if a user clicks the view button and views the app, can we take that action and let the sender of the notification know that the receiver has viewed / opened the app?
Short answer, Yes.
When the application starts due to a user electing to from a notification (local or remote) the application is started in a special way so that the application can process the notification. At this point it can do whatever you want, like send a message back to your service.
See Handling Local and Remote Notifications for details.