Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

on notification ios does not work on cold start #2654

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/ios/AppDelegate+notification.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ - (AppDelegate *)pushPluginSwizzledInit
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pushPluginDidFinishLaunchingWithOptions:)
name:UIApplicationDidFinishLaunchingNotification
object:nil];

[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(pushPluginOnApplicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
Expand Down Expand Up @@ -151,10 +156,29 @@ - (void)checkUserHasRemoteNotificationsEnabledWithCompletionHandler:(nonnull voi
}];
}

// This code will be called immediately after application:didFinishLaunchingWithOptions:. We need
// to process notifications in cold-start situations
- (void)pushPluginDidFinishLaunchingWithOptions:(NSNotification *)notification
{
NSLog(@"Push Plugin - createNotificationChecker");
if (notification)
{
NSDictionary *launchOptions = [notification userInfo];
if (launchOptions) {
NSLog(@"Push Plugin - coldstart");
self.launchNotification = [launchOptions objectForKey: @"UIApplicationLaunchOptionsRemoteNotificationKey"];
self.coldstart = [NSNumber numberWithBool:YES];
} else {
NSLog(@"Push Plugin - not coldstart");
self.coldstart = [NSNumber numberWithBool:NO];
}
}
}

- (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification {

NSLog(@"active");

NSString *firstLaunchKey = @"firstLaunchKey";
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"phonegap-plugin-push"];
if (![defaults boolForKey:firstLaunchKey]) {
Expand Down
14 changes: 13 additions & 1 deletion src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

#import "PushPlugin.h"
#import "AppDelegate+notification.h"
@import Firebase;
@import FirebaseInstanceID;
@import FirebaseMessaging;
@import FirebaseAnalytics;

@implementation PushPlugin : CDVPlugin
Expand Down Expand Up @@ -157,6 +157,18 @@ - (void)unsubscribe:(CDVInvokedUrlCommand*)command;
}
}

- (void)pluginInitialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];

}

- (void)finishLaunching:(NSNotification *)notification
{
NSLog(@"finishLaunching called");
self.notificationMessage = notification.userInfo;
}

- (void)init:(CDVInvokedUrlCommand*)command;
{
NSMutableDictionary* options = [command.arguments objectAtIndex:0];
Expand Down