Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to receive images in iOS notifications. #919

Open
adityathoutam opened this issue Jan 6, 2021 · 7 comments
Open

Unable to receive images in iOS notifications. #919

adityathoutam opened this issue Jan 6, 2021 · 7 comments
Labels

Comments

@adityathoutam
Copy link

[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:

  1. Build for iOS
  2. Deploy to Xcode and build
  3. Use generated token to send notifications via console
  4. Send text https image /image stored in bucket.
  5. 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
@chkuang-g
Copy link
Contributor

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.

@chkuang-g chkuang-g added needs-attention Need Googler's attention and removed new New issue. labels Jan 15, 2021
@charlotteliang charlotteliang self-assigned this Jan 15, 2021
@charlotteliang
Copy link

@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.

@charlotteliang charlotteliang added needs-info Need information for the developer and removed needs-attention Need Googler's attention type: question labels Feb 5, 2021
@adityathoutam
Copy link
Author

@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`

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Feb 8, 2021
@charlotteliang
Copy link

@chkuang-g can you try it in unity and see if this is reproducible.

@charlotteliang
Copy link

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.

@chkuang-g
Copy link
Contributor

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.

@charlotteliang charlotteliang removed their assignment Feb 17, 2021
@chkuang-g
Copy link
Contributor

chkuang-g commented Feb 25, 2021

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.

  1. (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 iOS App Crash ( podFile to use_frameworks! Issue when used ) #862

  2. Follow all of the steps from our sample readme.

  3. Follow this doc to add Notification Service Extension to your Xcode project and modify NotificationService.m (or NotificationService.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 your AppClips folder and change bundle id that match your Firebase project and your provision profile).

  4. Modify Podfile in your Xcode project. The basic idea here is you need Firebase/Messaging pod for both UnityFramework target and your new Notification Service Extension target (NotificationImage for your case, I assume). Your Podfile should look like the following

    source '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 iOS App Crash ( podFile to use_frameworks! Issue when used ) #862

  5. Run pod install under your Xcode project to regenerate Unity-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 iOS App Crash ( podFile to use_frameworks! Issue when used ) #862 (comment) to add the NotificationServiceExtension 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

@chkuang-g chkuang-g added needs-info Need information for the developer type: feature request and removed needs-attention Need Googler's attention type: question labels Feb 25, 2021
@chkuang-g chkuang-g removed their assignment Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants