Skip to content

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

@guntarspolis

Description

@guntarspolis

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%

Activity

google-oss-bot

google-oss-bot commented on Apr 2, 2020

@google-oss-bot

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

changed the title [-]Unity local notification plugin does not work with Firebase on iOS devices.[/-] [+][Local Notifications][Firebase] Opening app from notification does not show data on iOS devices[/+] on Apr 2, 2020
chkuang-g

chkuang-g commented on Apr 3, 2020

@chkuang-g
Contributor

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

guntarspolis

guntarspolis commented on Apr 4, 2020

@guntarspolis
Author

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.

added and removed
needs-infoNeed information for the developer
on Apr 4, 2020
guntarspolis

guntarspolis commented on Apr 6, 2020

@guntarspolis
Author
  • 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

patm1987

patm1987 commented on Apr 15, 2020

@patm1987

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

vishakh-av

vishakh-av commented on Apr 23, 2020

@vishakh-av

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!

25 remaining items

atelyk

atelyk commented on Aug 17, 2021

@atelyk

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.

3XclusiVe

3XclusiVe commented on Oct 9, 2021

@3XclusiVe

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.

voidtuxic

voidtuxic commented on Apr 1, 2022

@voidtuxic

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

meliksahd

meliksahd commented on Oct 19, 2022

@meliksahd

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

LeonardoDemartino

LeonardoDemartino commented on Feb 10, 2023

@LeonardoDemartino

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

supremepanda

supremepanda commented on Apr 25, 2023

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

MrlCrosl

MrlCrosl commented on Oct 18, 2023

@MrlCrosl

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?

kkfrank2

kkfrank2 commented on Apr 10, 2024

@kkfrank2

@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
Thanks for your solutoin. @jfperusse-bhvr . But when I upgrade mobile notification package to 2.2.2(for example), there is no UIApplicationDidFinishLaunchingNotification in UnityAppController+Notifications.mm. So I don't konw where to add the code snippet. Can you help me.

Mustafax06

Mustafax06 commented on Jun 5, 2024

@Mustafax06

This has been an open bug for 4 years and nobody cares. What a great team over there

smarty-concrete

smarty-concrete commented on Jun 7, 2024

@smarty-concrete

I've submitted a pull request here in the firebase-cpp-sdk repo which will hopefully address this issue.

keitanxkeitan

keitanxkeitan commented on Jun 21, 2024

@keitanxkeitan

@smarty-concrete Thank you for your contribution! I hope this change will be reviewed soon and the patch will be released!

a-maurice

a-maurice commented on Jun 27, 2024

@a-maurice
Collaborator

The latest release, https://github.com/firebase/firebase-unity-sdk/releases/tag/v12.1.0, has the fix provided by @smarty-concrete. Thank you for the contribution, hopeful that this addresses this long standing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @zbyhoo@alexames@keitanxkeitan@patm1987@stanislavsmagin

      Issue actions

        [Local Notifications][Firebase] Opening app from notification does not show data on iOS devices · Issue #377 · firebase/firebase-unity-sdk