-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to send push notifications from Swift ? #768
Comments
|
Thanks for your answer. In fact, when I am trying to send a push notification, it tells me that I need to use the master key in order to send it. However, from the swift code, I'm not sure if I can set the master key somewhere... |
Aha, here is something we uncovered then. The client SDKs don't have an ability to use MasterKey just yet, though we could safely add it, but it exposes a bad programming practice, since you should never put a master key on the client. |
So I need to have some code hosted somewhere (a web hosting) in order to send push notifications ? Isn't it possible to do that only by using Heroku and Swift code ? |
You can host Cloud Code actually on Parse Server. |
Also, here are two good guides on how to get Push Notifications in Parse Server land working with Cloud Code: |
Going to close out this issue, feel free to comment here or reopen it if you still having trouble sending push via Cloud Code. |
@nlutsenko Do you have a guide for how to trigger cloud code push notifications from my swift iOS app? Do I just paste this code in my main.js file then in swift call |
Yup, that would work just great as well. That repo tutorial is actually very very good. |
@nlutsenko Hey im still abit(very) lost. This is previously how I sent pushes in my messaging app. func sendPushNotification(contact: PFUser) {
let pushQuery = PFInstallation.query()
pushQuery?.whereKey("user", equalTo: contact)
let push = PFPush()
push.setQuery(pushQuery)
let pushDictionary = ["alert": PFUser.currentUser()!.valueForKey("name") as! String, "badge": "increment", "sound":""]
push.setData(pushDictionary)
push.sendPushInBackgroundWithBlock(nil)
} |
@nlutsenko Can I second @otymartin's comment about being lost. So I successfully got to Step 4 "Send Push Notifications" in the Parse Push tutorial https://github.com/ParsePlatform/parse-server/wiki/Push and have notifications working in my app from 'curl'. But that's where the tutorial seems to stop. I was hoping to request a notification directly from Swift code... Can you fill in the gap? I have no experience in cloud code, but I'm guessing what's missing is that I need to set up a function in cloud code with the appropriate parameters that I need to pass it, and then I need to call this function to dispatch the notification, is that correct? |
You could usw a Code like: You call the cloud fund with the Parms ["query" : YourQuery,"message" : PS: I'm not sure about the location of useMasterKey... I haven't gotten to
|
Thanks @hasso92 for your help. It was the push I needed to keep going, I had reached my input limit for the day! The Cloud code function I ended up using had similarities to the CloudPath example:
I then called it from Swift using the PFCloud.callFunctionInBackground method:
I go into this in more detail on my blog. |
here is the cloud code function that I modified to fits your requirements
swift code
|
hi, |
@fvimagination make sure that you have enabled the push notification at the xcode and make sure you push it from iOS real device and the one receiving it also an iOS real device |
@StevenArmandLee Push Notifications is enabled in Capabilities, but if i send a push from the iOS Simulator to a real device, it should work, right? |
fvimagination, I'm having the same issue. Did you ever figure out how to fix this? |
ok so it's my certificate that has a problem, therefore I re-created the certificate. |
@michaelsalvador that was my issue as well, now it works perfectly. |
@fvimagination So you're saying that after you recreated the development or production push certificate it sent to your device perfectly? Just to be clear |
@michaelsalvador yes, exactly, the code posted from StevenArmand works perfectly on my side, with Parse Server hosted on back4app.com |
Just solved this same issue. Will attempt to help, just @ me. |
@jbschaff best to document it here because others will experience the same problems and look for solutions. |
Will need to modify Swift code
Cloud code
Edit: Function to target all followers of User 1 is now solved.
|
Since the PFPush class is not working anymore, how can I send a push notification from Swift or how can I call some cloud code to send a push notification to my users ?
Example : User_1 sends a friend request to User_2. I want User_2 to receive a notification on his device. I know I can do this with Javascript / PHP, but is it possible to do it from Swift directly without having some files hosted on a web server ?
I am actually using Heroku.
Thanks,
Axel
The text was updated successfully, but these errors were encountered: