quickstart-unity
quickstart-unity copied to clipboard
Unable to receive images in iOS notifications.
[REQUIRED] Please fill in the following fields:
- Unity editor version: 2020.2.0f1
- Firebase Unity SDK version: 7.0.2
- Source you installed the SDK: UPM (.unitypackage or Unity Package Manager)
- Problematic Firebase Component: FCM (Auth, Database, etc.)
- Other Firebase Components in use: Auth,Database,Storage,RemoteConfig, FCM etc (Auth, Database, etc.)
- Additional SDKs you are using: AppsFlyer (Facebook, AdMob, etc.)
- Platform you are using the Unity editor on: Mac (Mac, Windows, or Linux)
- Platform you are targeting: iOS (iOS, Android, and/or desktop)
- Scripting Runtime: IL2CPP (Mono, and/or IL2CPP)
[REQUIRED] Please describe the issue here:
Unable to receive image notifications (rich) via console, sent to the Unity App
(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)
Steps to reproduce:
- Build for iOS
- Deploy to Xcode and build
- Use generated token to send notifications via console
- Send text + https image /image stored in bucket.
- Image is ignored, only text is received Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? What's the issue repro rate? (eg 100%, 1/5 etc) 100% What happened? How can we make the problem occur? This could be a description, log/console output, etc.
If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.
Relevant Code:
// TODO(you): code here to reproduce the problem
Hi @adityathoutam
Thank you for reporting the issue. Yes, I can reproduce the issue with quickstart on iOS as well.
Based on the Firebase iOS SDK doc, seems like there are several extra steps in Xcode to make it works, ex. Notification Service Extension.
The Xcode project generated from Unity is slightly complicated since it has two different targets, UnityFramework
and Unity-iPhone
. I am not sure if those steps from iOS SDK doc is valid. Will need to consult with our iOS team.
@adityathoutam As @chkuang-g mentioned, setup Notification service extension is a required step and you need to call the Messaging ExtensionHelper API inside the extension. Here's a tutorial you can check out: https://firebase.google.com/docs/cloud-messaging/ios/send-image Let us know if you already done that and it still doesn't work for you.
@chliangGoogle As @chkuang-g mentioned, Unity creates two different targets UnityFramework and Unity-iPhone. There are no instructions on what to do in this case. I have added the Notification service extension but I think it is not aware of the Firebase Messaging inside Unity. I have tried adding Firebase as pods dependencies, but Xcode is showing me 99+ errors. Here is the pod file `source 'https://github.com/CocoaPods/Specs.git' platform :ios, '11.0'
def shared_pods pod 'AppsFlyerFramework', '6.0.7' pod 'Firebase/Analytics', '7.0.0' pod 'Firebase/Auth', '7.0.0' pod 'Firebase/Core', '7.0.0' pod 'Firebase/Crashlytics', '7.0.0' pod 'Firebase/Database', '7.0.0' pod 'Firebase/Functions', '7.0.0' pod 'Firebase/Messaging', '7.0.0' pod 'Firebase/RemoteConfig', '7.0.0' pod 'Firebase/Storage', '7.0.0' pod 'PurchasesHybridCommon', '1.4.5' end
target 'UnityFramework' do shared_pods end
target 'Unity-iPhone' do target 'NotificationImage' do shared_pods end end`
@chkuang-g can you try it in unity and see if this is reproducible.
In regular iOS app, the Messaging needs to be installed inside service extension as well: https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseMessaging/Apps/AdvancedSample/Podfile
@chkuang-g will test on unity to see if it's the similar case.
Yes, I noticed that Unity generates multiple targets and has UnityFramework
embedded in Unity-iPhone
.
I have not try to set it up yet but I think that should be align with this sample.
https://github.com/firebase/firebase-ios-sdk/tree/master/FirebaseMessaging/Apps/AdvancedSample
Will keep you updated.
Alright, finally had a chance to crack this.
Here are all the steps you need to make it work. This has been tested with our quickstart project.
-
(Optional) Install Firebase
7.1.0
. It includes a couple of fixes for Podfiles and Xcode project which should make the following steps much easier. See https://github.com/firebase/quickstart-unity/issues/862 -
Follow all of the steps from our sample readme.
-
Follow this doc to add
Notification Service Extension
to your Xcode project and modifyNotificationService.m
(orNotificationService.swift
, if you prefer Swift ). Make sure you sort out the provision profile for this new target as well.When you have doubt, try to reference this iOS sample and see the difference in your Xcode project (Remember to copy your
GoogleServices-Info.plist
to yourAppClips
folder and change bundle id that match your Firebase project and your provision profile). -
Modify
Podfile
in your Xcode project. The basic idea here is you needFirebase/Messaging
pod for bothUnityFramework
target and your newNotification Service Extension
target (NotificationImage
for your case, I assume). Your Podfile should look like the followingsource 'https://github.com/CocoaPods/Specs.git' platform :ios, '11.0' target 'UnityFramework' do pod 'Firebase/Core', '7.5.0' pod 'Firebase/Messaging', '7.5.0' end target 'Unity-iPhone' do end # This should use the name of your Notification Service Extension target 'NotificationServiceExtension' do pod 'Firebase/Messaging', '7.5.0' end use_frameworks! # Use the following if you do not have other Swift framework pods for stability # use_frameworks! :linkage => :static
NOTE that I found that Xcode in general does not like to have the same pod added to multiple targets without
use_frameworks!
. This can be the reason of your complier error. Learn more about the nuisance in this thread https://github.com/firebase/quickstart-unity/issues/862 -
Run
pod install
under your Xcode project to regenerateUnity-iPhone.xcworkspace
.
And that's it. Should be working by now.
I can see several issues here.
- It is tedious.
- When you regenerate Xcode project, even incrementally, External Dependency Manager for Unity will override
Podfile
you modified for good, which can be extremely annoying. One possible workaround to alleviate the pain for now is to add a script like this https://github.com/firebase/quickstart-unity/issues/862#issuecomment-771546659 to add theNotificationServiceExtension
section automatically. - I did notice a different behavior between iOS sample and quickstart-unity. For iOS sample, the notification show up in the notification tray no matter the app is foreground, background or killed. And for quickstart-unity, the notification is only in notification tray IF the app is in the background or killed. This seems to be an inconsistent behavior.
Let me know if this helps. At the meantime, I will change this to a feature request
for all the frictions I described above (maybe a bug for the last one).
Shawn