firebase-unity-sdk icon indicating copy to clipboard operation
firebase-unity-sdk copied to clipboard

[Local Notifications][Firebase] Opening app from notification does not show data on iOS devices

Open guntarspolis opened this issue 5 years ago • 35 comments

Please fill in the following fields:

Unity editor version: 2019.2.17f1 Firebase Unity SDK version: 6.7.0 Source you installed the SDK (.unitypackage or Unity Package Manager): .unitypackage Firebase plugins in use (Auth, Database, etc.): Messaging Additional SDKs you are using (Facebook, AdMob, etc.): Facebook , Mobile Notifications(Package manager), Play Games Platform you are using the Unity editor on (Mac, Windows, or Linux): Mac/Windows Platform you are targeting (iOS, Android, and/or desktop): iOS/Android Scripting Runtime (Mono, and/or IL2CPP):IL2CPP

Please describe the issue here:

Unity local notification plugin does not work in some cases when firebase plugin is added.

Test case 1:

  1. Install Mobile Notifications
  2. Run some notifications
  3. Close app
  4. Open app from notification 5.1) receive callback about opening app from notification on Android [WORKS] 5.2) receive callback about opening app from notification on iOS [WORKS]

Test case 2:

  1. Install Mobile Notifications
  2. Install Firebase
  3. Run some notifications
  4. Close app
  5. Open app from notification

6.1) receive callback about opening app from notification on Android [WORKS] 6.2) receive callback about opening app from notification on iOS [DOES NOT WORK]

(Mobile Notifications)Android : iOSNotificationCenter.GetLastRespondedNotification();

(Mobile Notifications)iOS : AndroidNotificationCenter.GetLastNotificationIntent();

Please answer the following, if applicable:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)?

plugins works great without each other

What's the issue repro rate? (eg 100%, 1/5 etc)

100%

guntarspolis avatar Apr 02 '20 09:04 guntarspolis

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Apr 02 '20 09:04 google-oss-bot

Hi @guntarspolis

I do not think Analytics would do anything to notification at all. Could you offer a bit more detail?

  • Does this happen when you use Firebase quickstart, ex. Analytics quickstart. It will be very helpful if you can modify this project and provide the reproduction steps.
  • I'm curious if the issue occurs even if you did not call any Firebase API.
  • Could you provide some log when the issue occurs, from Unity editor and from Xcode? You could cross exam the log between your Test case 1 and Test case 2

Thank you

chkuang-g avatar Apr 03 '20 18:04 chkuang-g

Thank you for your response @chkuang-g . Yes, it was not Analytics , i spelled it wrong, its about Messaging. I'm sorry about that.

I'll go and reproduce all the three steps you mentioned.

Thank you.

guntarspolis avatar Apr 04 '20 07:04 guntarspolis

  • It does happen with Messaging quickstart.

Not working version:

  1. opened quickstart
  2. added Firebase messaging package
  3. add Mobile Notifications trough package manager
  4. added script to handle notification trigger and reading it from button click.

Working version:

  1. opened quickstart
  2. added Firebase messaging package
  3. add Mobile Notifications trough package manager
  4. added script to handle notification trigger and reading it from button click.
  5. remove all libs related to messaging

both versions here: https://drive.google.com/drive/folders/1r5GWFkTXK8r4RkP5iSdmMOD4aeOUSQca?usp=sharing

repro steps :

  1. build xcode project
  2. run game
  3. kill app
  4. run app trough notification that appears in 5 seconds
  5. click GetLastNotification button
  6. data shows up on screen (in working case, else it shows 'nothing!')
  • You don't have to call anything

  • There is no errors, it just ignores that I did open app from notification.

@chkuang-g

guntarspolis avatar Apr 06 '20 08:04 guntarspolis

This is being tracked as a bug internally. Definitely update this if you get any more information you'd like to share!

patm1987 avatar Apr 15 '20 17:04 patm1987

I am also facing the same issue with Mobile Notifications package of Unity when tried along with Firebase as mentioned above. When tried with the inbuilt local-notification services of Unity(https://docs.unity3d.com/ScriptReference/iOS.NotificationServices.html) instead of mobile-notifications-package along with Firebase, the same issue is there. In both the cases, I did not initialise Firebase though. This has become a headache and I hope this issue with Firebase is fixed soon!

vishakh-av avatar Apr 23 '20 09:04 vishakh-av

@patm1987 Do you have any ETA of this at the moment? It'll be helpful if you can tell an estimated time like few days/few weeks/months etc so we can plan our development accordingly.

vishakh-av avatar Apr 24 '20 08:04 vishakh-av

Hi! Could you please provide any ETA for this issue? Many thanks and good luck!

roberts1911 avatar May 18 '20 09:05 roberts1911

Hi @patm1987 We have the same issue. Do you have any workaround while Firebase SDK don't have a fix?Thanks.

vzlomvl avatar May 22 '20 08:05 vzlomvl

Hi @patm1987,

The issue seems to come from firebase-cpp-sdk.

When MessagingIsInitialized returns false in willPresentNotification, g_user_delegate is not being called (in this case, Unity Mobile Notifications). Note that this also causes an OS warning because the completionHandler is not called.

Maybe an easy fix would be to call the user delegate even if Messaging is not initialized yet?

Thank you!

jfperusse-bhvr avatar Jul 13 '20 20:07 jfperusse-bhvr

Hi @alexames Have you managed to reproduce the problem on your side and is the issue somewhere in your internal backlog (or it is on Hold)? I am wondering if I should wait for a fix or should I try to fix it myself (In case you have more high priority tasks and this task on hold). Thanks.

vzlomvl avatar Jul 21 '20 14:07 vzlomvl

Hi @chkuang-g Thanks for the reply. I tried to update pods dependencies to 6.27.1 but unfortunately it didn't fix the issue.

vzlomvl avatar Jul 27 '20 20:07 vzlomvl

We have the same issue. Unity 2018.4.16, MobileNotifications 1.3, Firebase AppCore and Firebase Cloud Messaging 6.15.2.

stanislavsmagin avatar Jul 28 '20 11:07 stanislavsmagin

Hello @alexames @chkuang-g Sorry for frequent motions but I really need your help. If the issue in Cpp part of the project we unable to fix it(because source which requires changes inside of the .a) =( We had planned to release a new version of the app soon and can't go live with this bug. Maybe you can provide an experimental fix(.a file with patch) to check the theory of @jfperusse-bhvr or any other workarounds?
Thanks.

vzlomvl avatar Jul 28 '20 14:07 vzlomvl

Hi @vzlomvl, sorry for the radio silence. I'm looking at this bug now. If I can find the root cause and get a fix, I'll look into getting you an experimental .a file or something for you to work with until we can get out another proper release.

alexames avatar Jul 28 '20 18:07 alexames

Hi @alexames. Thanks for the reply. If you need a small Unity project with the issue or any other additional information, please let me know.

vzlomvl avatar Aug 06 '20 10:08 vzlomvl

@vzlomvl @jfperusse-bhvr Hi guys! How did you fix it in your projects? Or you are waiting for fix by @alexames ?

stanislavsmagin avatar Aug 31 '20 16:08 stanislavsmagin

@stanislavsmagin In our case, we modified the mobile notifications package to force registering again as the UNUserNotificationCenter delegate in the UIApplicationDidFinishLaunchingNotification observer, but this is only a workaround until the fix is done to the firebase-cpp-sdk, which should call the delegate even if MessagingIsInitialized is false.

jfperusse-bhvr avatar Aug 31 '20 18:08 jfperusse-bhvr

@stanislavsmagin In our case, we modified the mobile notifications package to force registering again as the UNUserNotificationCenter delegate in the UIApplicationDidFinishLaunchingNotification observer, but this is only a workaround until the fix is done to the firebase-cpp-sdk, which should call the delegate even if MessagingIsInitialized is false.

I've also encountered this problem. @jfperusse-bhvr can you provide what changes have you made to make it work for the time being?

zbyhoo avatar Nov 02 '20 14:11 zbyhoo

We have the same issue. Are there any news about this, possible ETA? Is firebase team working on it at all?

mStratik avatar Nov 10 '20 17:11 mStratik

@zbyhoo In UnityAppController+Notifications.mm, at the beginning of UIApplicationDidFinishLaunchingNotification, we've added the following:

UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = [UnityNotificationManager sharedInstance];

Hope this helps!

jfperusse-bhvr avatar Nov 14 '20 00:11 jfperusse-bhvr

Ran into this issue as well, testing @jfperusse-bhvr 's fix. Is there a way to integrate those changes into the project proper instead of putting them into the UnityAppController.Notifications.mm file which is in the Package Cache?

Also - any updates on a solution here? I've seen some reports that reinstalling the packages helps, but no repo steps for getting it working.

GorillaOne avatar Jan 20 '21 20:01 GorillaOne

@GorillaOne I created an app controller subclass and retrieved information I want (in my case I wanted only notification title) directly from iOS using extern "C" function.

This way, when Xcode project is recreated during the build or new person is cloning and building the game, all is working still the same way.

https://gist.github.com/zbyhoo/7a9c8bfa64d1ecb7f6383ee8b179caf8

zbyhoo avatar Jan 20 '21 21:01 zbyhoo

It's still relevant for Unity editor version: 2020.3.9f1 Firebase Unity SDK version: 8.0.0 Mobile notifications: 1.4.2

Thanks @jfperusse-bhvr, it works. But it would be great to avoid hacks.

atelyk avatar Aug 17 '21 09:08 atelyk

Thanks to the above comment by @jfperusse-bhvr we also managed to fix the issue. Seems like this fix can be done without patching other plugins by adding something like this file to the unity project.

/* ApplicationStateListener.mm */
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AppDelegateListener.h"
#import "UnityNotificationManager.h"


@interface ApplicationStateListener : NSObject <AppDelegateListener>
+ (instancetype)sharedInstance;
@end

@implementation ApplicationStateListener
static ApplicationStateListener* _applicationStateListenerInstance = [[ApplicationStateListener alloc] init];

+ (instancetype)sharedInstance
{
    return _applicationStateListenerInstance;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        UnityRegisterAppDelegateListener(self);
    }
    return self;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark AppDelegateListener
- (void)didFinishLaunching:(NSNotification*)notification;
{
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = [UnityNotificationManager sharedInstance];
}
@end

P.S. Do not understand why firebase team ignore this problem for so long.

3XclusiVe avatar Oct 09 '21 20:10 3XclusiVe

hey team, any update on this? This is still occurring and definitely feels ignored by the team

voidtuxic avatar Apr 01 '22 11:04 voidtuxic

Thanks to the above comment by @jfperusse-bhvr we also managed to fix the issue. Seems like this fix can be done without patching other plugins by adding something like this file to the unity project.

/* ApplicationStateListener.mm */
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AppDelegateListener.h"
#import "UnityNotificationManager.h"


@interface ApplicationStateListener : NSObject <AppDelegateListener>
+ (instancetype)sharedInstance;
@end

@implementation ApplicationStateListener
static ApplicationStateListener* _applicationStateListenerInstance = [[ApplicationStateListener alloc] init];

+ (instancetype)sharedInstance
{
    return _applicationStateListenerInstance;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        UnityRegisterAppDelegateListener(self);
    }
    return self;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark AppDelegateListener
- (void)didFinishLaunching:(NSNotification*)notification;
{
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = [UnityNotificationManager sharedInstance];
}
@end

P.S. Do not understand why firebase team ignore this problem for so long.

this fix causes crashes when certain devices receive push notification signals (new gen iPad) we are trying to use post process scripts to edit unity notification package according to @jfperusse-bhvr 's solution

meliksahd avatar Oct 19 '22 08:10 meliksahd

We are having this same issue. Is there a fix yet?

LeonardoDemartino avatar Feb 10 '23 15:02 LeonardoDemartino

Thanks to the above comment by @jfperusse-bhvr we also managed to fix the issue. Seems like this fix can be done without patching other plugins by adding something like this file to the unity project.

/* ApplicationStateListener.mm */
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AppDelegateListener.h"
#import "UnityNotificationManager.h"


@interface ApplicationStateListener : NSObject <AppDelegateListener>
+ (instancetype)sharedInstance;
@end

@implementation ApplicationStateListener
static ApplicationStateListener* _applicationStateListenerInstance = [[ApplicationStateListener alloc] init];

+ (instancetype)sharedInstance
{
    return _applicationStateListenerInstance;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        UnityRegisterAppDelegateListener(self);
    }
    return self;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark AppDelegateListener
- (void)didFinishLaunching:(NSNotification*)notification;
{
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = [UnityNotificationManager sharedInstance];
}
@end

P.S. Do not understand why firebase team ignore this problem for so long.

this fix causes crashes when certain devices receive push notification signals (new gen iPad) we are trying to use post process scripts to edit unity notification package according to @jfperusse-bhvr 's solution

Is this solution still crashing? I could not found any solution other than this to solve problem. By the way, did you find a way to use post process scripts?

supremepanda avatar Apr 25 '23 15:04 supremepanda

Thanks to the above comment by @jfperusse-bhvr we also managed to fix the issue. Seems like this fix can be done without patching other plugins by adding something like this file to the unity project.

/* ApplicationStateListener.mm */
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AppDelegateListener.h"
#import "UnityNotificationManager.h"


@interface ApplicationStateListener : NSObject <AppDelegateListener>
+ (instancetype)sharedInstance;
@end

@implementation ApplicationStateListener
static ApplicationStateListener* _applicationStateListenerInstance = [[ApplicationStateListener alloc] init];

+ (instancetype)sharedInstance
{
    return _applicationStateListenerInstance;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        UnityRegisterAppDelegateListener(self);
    }
    return self;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark AppDelegateListener
- (void)didFinishLaunching:(NSNotification*)notification;
{
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = [UnityNotificationManager sharedInstance];
}
@end

P.S. Do not understand why firebase team ignore this problem for so long.

this fix causes crashes when certain devices receive push notification signals (new gen iPad) we are trying to use post process scripts to edit unity notification package according to @jfperusse-bhvr 's solution

Is this solution still crashing? I could not found any solution other than this to solve problem. By the way, did you find a way to use post process scripts?

Hi! Did u managed to fix this issue?

MrlCrosl avatar Oct 18 '23 08:10 MrlCrosl