Before the release of Delphi 10.3.2, Embarcadero released a patch for including FCM (Firebase Cloud Messaging) for Android in your apps, and now that support is included in Delphi 10.3.2. This article describes how to include support for iOS in FCM.
UPDATE: With many thanks to Antonello Carlomagno, the iOS implementation now has been tested more, and fixes applied as a result. Please update the demo files so that your iOS app will now receive events whilst the app is in the foreground or background.
TL;DR – The demo for including iOS in FCM is here. Note that it depends on other files in Kastri Free.
This solution is based around existing code that is used in my FCM solution, presented here. I created a unit (DW.PushNotification.iOS) which is similar to FMX.PushNotification.Android, that is meant as a “replacement” of sorts for FMX.PushNotification.iOS.
This new push notification unit uses other units from Kastri Free to provide the necessary implementation for iOS. It also relies on framework files from the Firebase 6.2.0 iOS SDK, however those that are required are also part of Kastri Free. The key things to remember for iOS when you’re including it in your own project are:
- Add GoogleServices-info.plist (download it from your project in Firebase Console) to your deployment (use a Remote Path of ./)
- Include -ObjC in the “Options passed to the ld linker” setting in the Linking options, which is under Building\Delphi Compiler in the Project Options. You’ll soon know if you’ve missed this because your app will crash on startup.
- Include paths to the Firebase SDK frameworks (these are in the Search path in the Project Options of the demo for iOS Device 64-bit configuration)
Go here for information on how to configure your app for FCM for Android.
As described above, the demo for this solution can be found here. It has had fairly minimal testing, so if you have any issues, please report them here.
Dave, you are my Hero!!!
Thanks Claudio! I assume that means it’s working for you?
I’m workng on it. I’ll let you know as soon as I finish the tests. Many thank’s!
Please be aware that the demo has been updated to fix a couple of issues 🙂
Dear Dave.
My firemonkey version is 10.3.2.
I compiled as you’r described but I get an error
[DCC Errror] E2597 Id: file not found: UserNotificatins for architecture arm64.
Does KastriFree’s FCM demo support iOS 64bit?
Thank you always.
Hi Jeff,
You’ll need to add the UserNotifications framework to the iOS SDK. To do this, in Delphi:
Go to Tools|Options and on the left select Deployment > SDK Manager, and select the iOS SDK you are using.
In the Remote Paths list, scroll down to the section called “Frameworks” and select one of them
Click the “Add a new path item” button on the right
In the Path on remote machine box, enter: $(SDKROOT)/System/Library/Frameworks
In the Framework name box, enter: UserNotifications (Do not check any of the radio buttons)
Click OK
Click Update Local File Cache
Click Save
That should have it compiling
Thank you for your quick response!!
As you just told me the build was successful and I got a Token.
Thank you very much!!
But .. FCM messages are not being received. (Using FCM Console) ^^;
I’ve found that sending messages to iOS from the Firebase Console does not work. Please use this tool to test:
https://www.apnstester.com/fcm/
..and check the JSON checkbox. It prefills the edit box with template JSON. Note that if you use this to test sending to Android, you will need to change the JSON, as per the example towards the very bottom of this article:
http://delphiworlds.com/2017/05/add-firebase-cloud-messaging-mobile-apps-part-1/
Thank you very much for you’r so fast answer.
im succeded!!
I was impressed by your kindness!
You’re my hero too !! ^^
Hi there, been using your Push Notification solutions for a few months now, thank you very much.
But I have a problem getting the Demo to work (Delphi 10.3.3 & iOS 13)
I get the token, but will not receive Push Notifications (not even with the apnstester). I looked into the device logs, with the iPad connected to the mac, and this is what I get from there:
SpringBoard(UserNotificationsServer)
‘Push Registration with a nil environment was encoutered, will not invalidate token’
Any idea what the problem is? Thank you.
Hi Francisco,
You may have to include more of the messages from the logs to give a better idea of what the problem is. If you’re receiving a token but no message, it’s possibly related to your APNs Authentication Key (which is a configuration item in Firebase Console)
[…] in October last year, I wrote about integrating iOS support for FCM using Embarcadero’s implementation. In this article, I describe a revised demo that simplifies things and fixes a couple of […]
Hi Dave,
I tried with demo but on compile I get this error: [DCC Error] DW.PushNotification.iOS.pas(29): E2291 Missing implementation of interface method UNUserNotificationCenterDelegate.userNotificationCenter
Can you help me?
Hi Alfredo,
Do you have the latest version of all the files? I just downloaded Kastri Free as a .zip file, unzipped it and compiled the demo and it compiled with no errors.
Which version of Delphi are you using?
Hi dave, thanks for reply.
I downloaded by svn from github and compiled on Delphi 10.3.3: error!
I met the same problem :
DW.PushNotification.iOS.pas(29): E2291 Missing implementation of interface method UNUserNotificationCenterDelegate.userNotificationCenter
I comment out three procedures in DW.iOSapi.UserNotifications.pas
UNUserNotificationCenterDelegate = interface(IObjectiveC)
// [MethodName(‘userNotificationCenter:openSettingsForNotification:’)]
// procedure userNotificationCenter(center: UNUserNotificationCenter; notification: UNNotification); overload; cdecl;
Hi Dave,
How to use subscribeToTopic ?
I found it in DW.iOSapi.Firebase.pas > FIRMessaging = interface(NSObject)
There’s some documentation about it, here: https://firebase.google.com/docs/cloud-messaging/ios/topic-messaging
Thank you.
I use this and it works.
FMessaging.subscribeToTopic(StrToNSStr(‘my_test’));
I have another problem, when app is in background iPhone showed the notification bar.
But when app is in foreground it doesen’t fire
NotificationCenterReceiveLocalNotification
or
OnReceiveNotificationEvent
So I can’t get data from FCM remote notification to process in my app.
Hello Tony,
I wrote a small test app for IOS by using Kastri Free library, the test was ok on my ipad, I can receive notifications from Firebase cloud messaging. but when I tried to subscribe one topic from ipad, I got error message,
I tried the method you recommended( from DW.iOSapi.Firebase) as follow, but got “access violation” by taping a button on my ipad.
var _FMessaging: FIRMessaging;
begin
_FMessaging.subscribeToTopic(StrtoNSstr(‘test’)) ;
end
Could you give a help?
Thanks in advance!
You should be using the later support for FCM, for which there is a demo, here. It has a SubscribeToTopic method available.
Dave, How can I use KastriFree in delphi? You say the demo needs parts of it. I`m having this message in the demo project
[DCC Error] E2597 ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Analytics\FirebaseAnalytics.framework’
ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Analytics\FirebaseCore.framework’
ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Analytics\FirebaseCoreDiagnostics.framework’
ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Analytics\FirebaseInstanceID.framework’
ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Analytics\GoogleAppMeasurement.framework’
ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Analytics\GoogleUtilities.framework’
ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Analytics\nanoPB.framework’
ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Messaging\FirebaseMessaging.framework’
ld: warning: directory not found for option ‘-L..\..\ThirdParty\Firebase\iOS\Firebase.6.2.0\Messaging\Protobuf.framework’
ld: warning: directory not found for option ‘-L..\..\API’
ld: warning: directory not found for option ‘-L..\..\Core’
ld: warning: directory not found for option ‘-L..\..\Include’
ld: file not found: /System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration
Thanks alot for your attention
If you’re compiling a demo, it has paths to the library code and other dependencies, which is why you are seeing those errors. If you move the demo, you’ll need to update the paths to point to the correct locations.
To resolve the last error regarding SystemConfiguration, you will need to add frameworks to the SDK, as per the instructions in the “Configuration” section of this article: http://delphiworlds.com/2018/08/firebase-cloud-messaging-revisited/
Dear Dave.
I used DW.Firebase.Messaging
FCMTokenReceived it works
bat subscribeToTopic not works, message Error is “Invoke error: method not found”
Hi Dave,
I’m getting this error
[DCC Error] E2597 ld: file not found: ImageIO for architecture arm64
Hi Dave
I finaly got this all working in both ios and android. I just got a small issue on ios, there no sound when I receive the notification.
Hi Dave,
I have all notifications working in android and ios. In Android and Ios there no default sound played.
Thank you
For Android version 6 or greater, you need to assign the sound to the notification channel. For iOS, you need to have a “sound” property in the notification payload, e.g:
"notification": {
"body": "test",
"title": "test",
"sound": "default"
}
Hi dave,
I try to send the notification, and i have the sucess message, but does not appear in ios device.
Hi Samuel,
Success message, where? Are you using PushIt? When you say “does not appear in ios device”, do you mean no banner appears, or is nothing received on the device at all?
If it is just no banner appearing, please ensure your app has a value for CFBundleIdentifier in Project Options that matches the App ID being using for the provisioning profile (configured on the Apple Developer site), and that the App ID has Push Notifications enabled. If it does not, you need to enable it, and re-create the provisioning profile.
Hi Dave,
I’m trying to test this on Delphi 10.4.1, I tried with IOS 8, 9 and 10 with Firebase 6.18 but was missing frameworks… then I tried on 11, 12 but Undefined symbols for architecture arm64 error.
Then I tried with IOS 14.2 and Firebase 7.4 but:
[DCC Error] E2597 ld: file not found: GoogleAppMeasurement for architecture arm64
what cant I do to solved, can you help me?
Thank you
Hi Jorge,
There’s an issue with the linker in Delphi 10.4.1 that prevents it from working with newer iOS libraries such as Firebase (I think from version 7 onwards). This issue has been reported to Embarcadero.
Also, there was a follow-up article that has an improved demo:
https://delphiworlds.com/2020/01/expanding-embarcaderos-fcm-implementation-revisited/
The newer demo works with the Firebase SDK that is in the repo:
https://github.com/DelphiWorlds/KastriFree/blob/master/ThirdParty/Firebase/iOS/Firebase.6.16.0.zip
So please use that one, unzipping it first, of course. The structure for the Firebase SDK has been changing over time – the paths in the newer demo should suit this SDK
For people who is searching how to subscribe topics on iOS:
uses
Macapi.Helpers,
iOSapi.FirebaseMessaging,
….
var
MessagingInstance: FIRMessaging := TFIRMessaging.Wrap(TFIRMessaging.OCClass.messaging);
MessagingInstance.subscribeToTopic(StrToNSStr(aTopic));