Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
App publishers can send push notifications at any time; users donāt have to be in the app or using their devices to receive them. They can do a lot of things; for example, they can show the latest sports scores, get a user to take an action, such as downloading a coupon or let a user know about an event, such as a flash sale. (by Urbanairship)
Adding push notifications to your app is not only a great way to improve the user experience. If used smart, it also helpsĀ to:
- Stimulate user engagement
- Retain users
- Increase conversion rates
Recently our team implemented push-notifications for React-Native iOSĀ app.
We spent a couple days to get this fully working for most common scenarios. The goal of this article is to save this time forĀ you.
Apple Push Notification service (APNs) is the centerpiece of the remote notifications feature. It is a service for app developers to propagate information to iOSĀ devices.
Application backend developer is indicated as the Provider on scheme above. We use APNs to propagate notifications to target devices. To achieve it, we need to ask userās permission. When the user allows a permission request, the mobile app subscribes to notifications on APN. As a result, APN sends to the client a unique deviceĀ token.
Now, this token has to be transferred to the backend and stored. When the backend decides to send a push notification, it should pass this token to theĀ APN.
In this article, we implement push-notifications sending and handling in React-Native iOS app (RNĀ 0.57)
Part I: MobileĀ App
Our current project is built with native code, using react-native init command. Although these instructions may be applied to the ejected Expo project. We use PushNotificationIOS package from the official RNĀ API.
Step 1: Manually Link PushNoficationIOS library
Regarding official docs, you needĀ to:
- Find node_modules/react-native/Libraries/PushNotificationIOS/RCTPushNotification.xcodeproj
2. Drag this file to your project on Xcode (usually under the Libraries group onĀ Xcode)
3. Click on your main project file (the one that represents theĀ .xcodeproj), select Build Phases and drag the static library from the Products folder inside the Library you are importing to Link Binary With Libraries
Step 2: Augment AppDelegate content
At the top of your AppDelegate.m:#import <React/RCTPushNotificationManager.h>
And then in AppDelegate.m implementation add the following:
Step 3: Adjust the Xcode projectĀ settings
Open project in settings Xcode, choose Capabilities settings
Step 4: Finally write some codeĀ :)
This component handles all received push notifications when the app is opened or closed. Now you may put <PushNotificationHandler /> in root component of your app to make sure it will be mounted when the app isĀ started.
Part II: ServerĀ Side
Requirement: You should have a valid Apple Developer Program Membership (100$/year).
Step 1: Ensure the correct Bundle Identifier
Check in XCode/General project settings if the, Bundle Identifier is the same as you have in Apple Store Connect/App Information
Step 2: Generate APNs AuthĀ Key
To be able to use APN, you need to create and use app key for authorization.In your Apple Developer Account, openĀ Keys:
Click on +Ā Icon
In the next page, enter a name for your key, enable APNs and click Continue at the bottom of theĀ page.
Apple will generate aĀ .p8 key file containing your APNs AuthĀ Key.
Save Key ID, you will need it for the nextĀ step.
Now, click on Certificates/All and download your certificate withĀ .cer extension. Save this file as ios_development.cer and put to repoās rootĀ folder.
Also find and save Team ID. To get it, login to developer.apple.com. In the top right corner click under your name -> ViewĀ Account.
Step 3: Send a Push notification
In the sample repo you will find pushServer.js. Launch it with params:node pushServer.js keyId teamId token appIdĀ message
Complimentary repo for theĀ article:
ProductCrafters/react-native-ios-push-notifications-example
Used article:https://eladnava.com/send-push-notifications-to-ios-devices-using-xcode-8-and-swift-3/
š My team uses JS and React and React Native to build production apps over 3 years. We help US startup founders to bring their ideas to life. If you need some help, send a message āļø oleg@productcrafters.io
Complete Guide: Receive Push Notifications in React-Native iOS app was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.