ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

didReceiveRemoteNotification:fetchCompletionHandler not called. #357

Closed RoyDeng closed 2 years ago

RoyDeng commented 2 years ago

I set contentAvailable to true, but it didn't work.

message = new gcm.Message({
    priority: 'high',
    contentAvailable: true,
    data: {
        notification_type: 1,
        ...
    },
    notification: {
        title: '測試',
        body: '測試',
        sound: 'default'
    }
});
eladnava commented 2 years ago

Hi @RoyDeng, 1) iOS Silent Notifications require the Background Modes -> Remote Notifications capability to be enabled. Please ensure this capability is enabled in your Xcode project settings, and try sending a silent notification with contentAvailable: true again.

2) Please ensure your app has not been swiped away (killed) as this will prevent silent notifications from waking up your app (this is an Apple iOS platform restriction).

3) If testing using the Xcode debugger, please note that the debugger won't break on didReceiveRemoteNotification:fetchCompletionHandler if your app is not in foreground when a silent notification comes in.

RoyDeng commented 2 years ago

Thanks for your response. I would like to confirm that this setting is equivalent to content-available: 1 in notification? Also, I enabled remote notifications capability in the background Modes, it still doesn't work.

eladnava commented 2 years ago

Hi @RoyDeng, Yes, setting contentAvailable: true will lead to content-available: 1 being passed to the APNs server and a silent notification being sent.

Please confirm items 2 and 3 are not the cause as well (app not killed/not being debugged in background).

RoyDeng commented 2 years ago

I have solved the problem, thanks.

eladnava commented 2 years ago

@RoyDeng please let us know what the underlying cause of the problem was and how you fixed it as it may help other developers in the future facing the same issue.

On Thu, Sep 2, 2021, 12:52 AM Roy Deng @.***> wrote:

I have solved the problem, thanks.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ToothlessGear/node-gcm/issues/357#issuecomment-911278051, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBQZTI6SQBOD5NUDH37B3DT74NMHANCNFSM5DGSXFRQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

RoyDeng commented 2 years ago

Hi, I found that I also use didReceive and didReceiveRemoteNotification at the same time. Based on the life cycle, it does not call the function I expect.