from client side (ObjC)
This section explains how you can send push notifications through your iOS client with Back4App.
This is how it will look like:
At any time, you can access the complete Project built with this tutorial at our GitHub repository.
To complete this quickstart, you need:
- An app created at Back4App.
- An iOS app connected to Back4App.
- Note: Follow the Install Parse SDK (Swift) Tutorial to create an Xcode Project connected to Back4App.
- An iOS device, iphone or ipad, running iOS 10 or newer.
- A paid Apple developer Account.
Going forward we are going to assume you have completed all steps of the Back4App Push Notifications via Dashboard tutorial, even if you use the iOS Project built with this tutorial that is available at our GitHub repository. You should have basic push notifications working and also be able to send pushes out via the admin console.
- Find the “Core Settings” block and click on SETTINGS. The “Core Settings” block looks like this:
3. Scroll to the end of the page and click on the EDIT DETAILS button, as shown below:
4. You will see a checkbox called Allow Push Notification from Client in the end of the edit page, tick that box and click on the SAVE button, as shown below:
- Assuming you have completed the Back4App Push Notifications via Dashboard tutorial, you will want to modify the completed project from that tutorial or download it from our GitHub repository. First, you will add a channel to your Installation object. You are going to do this by altering the method createInstallationOnParse in your AppDelegate file. Open your project’s AppDelegate.m file and add the following line of code - ‘[currentInstallation setObject:@[@”News1”] forKey:@”channels”];’ - which will set the installation object’s channel array to contain one channel called News.
This will allow you to send a message to everyone who subscribes to the channel called News via cloud code
Make sure your version of didRegisterForRemoteNotificationsWithDeviceToken is the same as the code below.
2. Next, we will add a method to your app delegate to send a push to the News channel everytime the app launches. Open your project’s AppDelegate.m file and the method below and make sure this method is fired off everytime the app launches by calling it from didFinishLaunchingWithOptions.
AppDelegate.swif
Open your app from the simulator while leaving your physical device closed with the lock screen on.
You should see the pushes appear on your device’s lock screen as soon as the app opens on the simulator.
You should have a firm understanding of how to send pushes from the client.
You can combine it with a pfquery to target users based on some sort of property like age, location, or object id.
Just remember that if client push is enabled it can be exploited and can’t be turned off without restricting all client pushes. It’s recommended that you tick to pushes from Cloud Code, but it’s still good to know.
At this stage, you can send push notifications using Client Push through Back4App!