I am currently learning【Swift 4】 to expand my programming knowledge. I looked at Swift a few years ago, but am now ready to dive into it.
I have programmed for many years with Java, and have some familiarity with Python. So, my approach to learning a new language is influenced by that previous knowledge.
☞ Step1: Create an empty project on XCode
a. Choose `Single View App`
b. Make sure you provide a unique package name.
c. Enable capabilities Remote notifications & Push notifications
Click on .xcodeproj -> Capabilities -> Enable Push Notification
☞ Step2: Install requirements using Pod
Requirements such as Firebase & FirebaseMessaging. Before installing make sure that your machine is installed with Cocoapods. If not installed, no worries it is easy to install from here.
// open terminal and run below command
$ cd /your-project-directory///Use this command to initialise the pods
$ pod initPost this command Podfile will be creating in project root directory//Use vi or vim editor(whatever is installed on your machine)
$ vim Podfile
//proceed to install added Pods
$ pod install
☞ Step3: Setup firebase account
a. Create project from here
b. Enter into your created project from the firebase console. Choose the application environment, Android/iOS/Web. Make sure your package name (or bundleId) is same as you entered while setting up XCode application.
c. Add config file(generates from the above process) to project root directory: GoogleService-Info.plist
☞ Step4: Setup certificates at Apple account
a. Register your app ID from here https://developer.apple.com/account/ios/identifier/bundle/create and in App services section, make sure you tick/select Push notifications checkbox.
b. APN(Apple Push Notifications). To enable push notifications, we need to submit CSR.
Create CSR from the MAC — Keychain Access. Enter required details. Choose “Saved to disk” option while requesting a certificate.
d. In the Apple console, you need to upload this CSR certificate.
e. After the above step, you will be able to download APN certificate. Open this certificate by double-clicking it. Then choose the Export option, which will be saved .p12 certificate.
☞ Step5: Firebase app configure
In the section iOS app configurations>>APN certificates>> Choose development or production certificates(based on your previous setup). Upload p12 certificate by clicking the upload button.
☞Step6: Swift4 coding for Push notification
Here I am attaching firebase official git repo — code snippets. You can directly Copy + Paster complete class. Easy understandable.
☞Step7: Trigger message using NodeJS/Java/Python/Go
Firebase console will be providing the required basic code snippets in different programming languages. Post clicking on Generate new private key
you will be able to download serviceAccountKey.json
.
Here I am adding the code which I configured with NodeJS environment.
☞Step8: Notifications delivered.
✎ References
- https://firebase.google.com/docs/cloud-messaging/ios/client
- https://github.com/firebase/quickstart-ios/tree/904fbc06bd69363782314a9d027f6300d054c1b3/messaging/MessagingExampleSwift
- https://stackoverflow.com/questions/46646918/error-use-of-undeclared-type-messagingdelegate-in-firebase-messaging
- https://stackoverflow.com/questions/27324020/no-valid-aps-environment-entitlement-string-found-for-application-on-app-store
Happy Exploration
Learn – Grow – Glow
Reach me at LinkedIn