is it possible to unsubscribe in safari?
publicocean0 opened this issue · 13 comments
i m working based on your code. For now front-end part.
I saw there is a missing part in safari.
You execute the subscription directly but if i want unsubcribe the notification using a html button as is possible in notsafari browsers? In rest api there is delete api. In js exists a api for deleting a pushid?
Hi, I think you have understood that implementing push notifications to a website and web application are different scenarios, Because, website doesn't have its own back-end. Safari push notification protocol is mainly designed for websites. Therefore, standard way and approach for web applications can be different.
Standard way of unsubscribe [for websites]
- A user removes permission of a website in Safari preferences.
- Your safari back-end receives HTTP
DELETE
request with client'sauthentication token
- Then your safari back-end deletes relevant user from the database.
Reference: Apple's developer guide, Section "Forgetting Device Permission Policy"
Customized way of unsubscribe [for webapps]
- A user clicks on some button labeled like stop notifications.
- Web application notify this to its back-end using existing communication channel
NOTE: a webapp has its own way of communicating with its back-end. such as REST, Websockets, etc. If you don't have a webapp backend, you have to create simple one may be php+mysql which is capable of persisting or removing data according to client side requests
- Webapp back-end removes existing subscription token from database. (users who don't have a subscription token are not supposed to deliver messages)
@publicocean0 Did I answer your question?
the second one: Customized way of unsubscribe. I thought to send a delete ajax request to server for delete the notification.For you it can work?
if you want we can share code fir making a a generic library
Can you please mention your question little bit more clearly? What do you suppose me to do?
if (isSubscribed) return new Promise(function(ons,oner){
ajax(wsURL+'/1.0/devices/'+token+'/registrations/'+pushId,'DELETE').then(x => ons({result:'unsubscribed',id:pushId})).catch(err => oner({result:'internal',details:err,id:pushId}));
});
i m trying to align the behaviour in safari to the not safary api. So for unsubscribing ...
it remove the subscription in the server. I dont know if it work for apns
i m emproving js and java part for be general.
first part https://github.com/publicocean0/notificationManager. It is not tested ... i m a bit running ... :)
the proposal is ... i m producing a general solution also for backend ...
i can send all the code to you. You tell me if it works :) Then you can use all :) A little collaboration :)
Your proposal
Well. Then in your generic implementation, have a function unsubscribe
function unsubscribe(){
if(isSafari){
unsubscribe_safari();
} else {
unsubscribe_non_safari();
}
}
function unsubscribe_safari
will say to the browser and to back-end to stop notifications and delete the subscription. function unsubscribe_non_safari
will say to back-end to delete the subscription and not to send notifications.
Your back-end should be able to identify client request and delete the relevant subscription token.
Collaboration
If you would like to collaboratively build the idea, I think first thing should do is make an environment you can test my implementation. Then universal_web_notification_sender should be extended to support REST requests (using Servlets, Jersy etc). Database model should be implemented to store subscription details. So on have to go.
Scope
FYI, the scope of this project was to provide as much as possible simple code base to add push notifications support to an existing web application. But your suggestion actually going to make an web application too.
yes my previous block code is not correct because this uri is not for subscribing the user but the device.... computing ...
I used a lot of clousure in the code so there is no useless variables in memory
I m finishing to developop rest &db provider. It creates the package on the fly in java.
now i m passing to sender
ah about scope ... it is opposite .... i dont implementing a war but a generic library. It use just servlet api