Push notification on iOS by using FireBase

Hi,
Is there any sample, reference, guide, or tutorial about how to integrate FireBase push notifications into iOS?
Android is straightforward and so easy, but iOS seems to be too tricky and challenging!
Any thoughts and ideas would help!
Thank you.

I will give 50 USD as a reward to anyone who provides a full tutorial or github repository for this subject.

there’s plenty of youtube tutorials like this Swift: Push Notifications Tutorial (2023) – iOS Development - YouTube but mainly you’ll need an apple computer to access xcode and the apple developer console to turn on push notifications for ios

Honestly, I’m new to iOS development, but I think adding push notifications to cc iOS native project is not as easy as Swift project is.

that’s okay, I’ve been in iOS development since 2015 and its the same process for any game or app, but you are required to have a MacOS device and an apple developer account.

So once you build the ios project from CC, you can open it in Xcode and do the same process. the code may be different tho. I skimmed this doc maybe have a look to get some insight: Cocos Creator 3.8 Manual - iOS Publishing Example

iOS push notifications are tricky but once you successfully done the first time, it’ll be easy to implement in the future.

Yes, I have all the needed stuff for iOS development. I’ve built iOS and it worked properly, I’ve tried to follow such tutorials but I couldn’t add push notfi to iOS.

Can I see screenshots of where you implemented the code and where it triggers? I’m assuming it uses Obj-c?

I removed those projects due to they got messy!
But, here is the last iOS native project

Okay so firebase isn’t imported in the screenshot? Have you got it working on a regular app before? if not I recommend doing that first then when you have a good understanding, then transfer it over to your game

No, let me try it!

1 Like

At the first step, seem CocoaPod is not compatible with CC iOS project!

What makes you think that? did it work on a regular app?

No, after checking, I found it is a warning.
Now, I can obtain FCM registration token but I can’t receive notifications on iPhone.

Yeap, finally I could send a notification!
I’ll write how to do it here!

Here is the solution of Managing push notifications on iOS!

Part One : Project setup
1- Install CocoaPods brew install cocoapods
2- Go to iOS project dircd /<your project>/build/ios/proj
3- Run this command pod init . Ignore the warning. A file with name of “Podfile” will be generated.
4- Open “Podfile” with a text editor.
5- Edit the content of Podfile as follow

target '<projectname>' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  pod "Firebase/Core"
  pod "Firebase/Messaging"
end

In my case project name is Xpell-mobile

6- Run pod install
7- After installing <ProjectName>.xcworkspace file will be generated open this file with XCode
8- Add GoogleServices-Info.plist file to /<your project>/native/engine/ios
9- Change AppDelegate.h and AppDelegate.cpp like following gist

Structure of your project must be something like this

DONE!
Now, if everthing has been set correctly, by running your project from Xcode you will find FCM Registration Token in Xcode console!

Important tips:
1- Don’t forget to add push notification capability to your project

2- Don’t forget to upload your *.p12 certificate file to Firebase for your project.

3- If you rebuild iOS from CC you must do steps 6, 8, and tip 1 again!!

In the next part I will write about how to send FCM to the game.

3 Likes

Congrats on figuring it out! Hopefully this post will help others as well

1 Like