didReceiveRemoteNotification: is not called after notification arrives and app is in background/suspended...
Within AppDelegate
I simply update applicationIconBadgeNumber
:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
application.applicationIconBadgeNumber += 1
}
Everything works as expected when the app is connected to Xcode and is in debugger mode. But just after I plug it out from Xcode, notification arrives but badge is not updated. App is in background mode.
Why? What is wrong with my approach? Please, give me an advice🏆
ios swift push-notification
add a comment |
Within AppDelegate
I simply update applicationIconBadgeNumber
:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
application.applicationIconBadgeNumber += 1
}
Everything works as expected when the app is connected to Xcode and is in debugger mode. But just after I plug it out from Xcode, notification arrives but badge is not updated. App is in background mode.
Why? What is wrong with my approach? Please, give me an advice🏆
ios swift push-notification
add a comment |
Within AppDelegate
I simply update applicationIconBadgeNumber
:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
application.applicationIconBadgeNumber += 1
}
Everything works as expected when the app is connected to Xcode and is in debugger mode. But just after I plug it out from Xcode, notification arrives but badge is not updated. App is in background mode.
Why? What is wrong with my approach? Please, give me an advice🏆
ios swift push-notification
Within AppDelegate
I simply update applicationIconBadgeNumber
:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
application.applicationIconBadgeNumber += 1
}
Everything works as expected when the app is connected to Xcode and is in debugger mode. But just after I plug it out from Xcode, notification arrives but badge is not updated. App is in background mode.
Why? What is wrong with my approach? Please, give me an advice🏆
ios swift push-notification
ios swift push-notification
edited Nov 16 '18 at 10:29
Bartłomiej Semańczyk
asked Nov 16 '18 at 6:58
Bartłomiej SemańczykBartłomiej Semańczyk
34.4k25170238
34.4k25170238
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
Push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.
You can send the badge number in the payload of the push notification,
Payload could look like this:
{
"aps" : {
"alert" : "Notification REceived",
"badge" : 1
}
}
add a comment |
You need to check in didReceiveRemoteNotification
with fetchCompletionHandler
of UNUserNotificationCenter
delegate method
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
messagingManager?.appDidReceiveMessage(userInfo)
}
I updated the question. My delegate method is not called when app is in background mode and not connected to the debugger;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:17
Have you confirm delegate UNUserNotificationCenter.current().delegate = self inside application(_:didFinishLaunchingWithOptions:) method
– iParesh
Nov 16 '18 at 7:18
Yes, I can confirm;) That method is called when app is connected to the debugger, but doesnt work when not connected to the debugger. Why?
– Bartłomiej Semańczyk
Nov 16 '18 at 7:21
What makes the difference with that two methods?;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:33
add a comment |
I found this post very helpful for managing notifications in the background, basically you have to use the call with completion handler.
didReceiveRemoteNotification when in background
add a comment |
Your messagingManager
is an optional. You should check, that it isn't nil
. If it is nil
, the appDidReciveMessage()
function would not be triggered
It is not nil;) it works when app is connected to the debugger
– Bartłomiej Semańczyk
Nov 16 '18 at 7:07
Did you check also that it isnt nil when your App is in Background?
– Jonathan
Nov 16 '18 at 7:10
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332889%2fdidreceiveremotenotification-is-not-called-after-notification-arrives-and-app-i%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.
You can send the badge number in the payload of the push notification,
Payload could look like this:
{
"aps" : {
"alert" : "Notification REceived",
"badge" : 1
}
}
add a comment |
Push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.
You can send the badge number in the payload of the push notification,
Payload could look like this:
{
"aps" : {
"alert" : "Notification REceived",
"badge" : 1
}
}
add a comment |
Push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.
You can send the badge number in the payload of the push notification,
Payload could look like this:
{
"aps" : {
"alert" : "Notification REceived",
"badge" : 1
}
}
Push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.
You can send the badge number in the payload of the push notification,
Payload could look like this:
{
"aps" : {
"alert" : "Notification REceived",
"badge" : 1
}
}
answered Nov 16 '18 at 7:37
JunaidJunaid
59110
59110
add a comment |
add a comment |
You need to check in didReceiveRemoteNotification
with fetchCompletionHandler
of UNUserNotificationCenter
delegate method
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
messagingManager?.appDidReceiveMessage(userInfo)
}
I updated the question. My delegate method is not called when app is in background mode and not connected to the debugger;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:17
Have you confirm delegate UNUserNotificationCenter.current().delegate = self inside application(_:didFinishLaunchingWithOptions:) method
– iParesh
Nov 16 '18 at 7:18
Yes, I can confirm;) That method is called when app is connected to the debugger, but doesnt work when not connected to the debugger. Why?
– Bartłomiej Semańczyk
Nov 16 '18 at 7:21
What makes the difference with that two methods?;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:33
add a comment |
You need to check in didReceiveRemoteNotification
with fetchCompletionHandler
of UNUserNotificationCenter
delegate method
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
messagingManager?.appDidReceiveMessage(userInfo)
}
I updated the question. My delegate method is not called when app is in background mode and not connected to the debugger;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:17
Have you confirm delegate UNUserNotificationCenter.current().delegate = self inside application(_:didFinishLaunchingWithOptions:) method
– iParesh
Nov 16 '18 at 7:18
Yes, I can confirm;) That method is called when app is connected to the debugger, but doesnt work when not connected to the debugger. Why?
– Bartłomiej Semańczyk
Nov 16 '18 at 7:21
What makes the difference with that two methods?;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:33
add a comment |
You need to check in didReceiveRemoteNotification
with fetchCompletionHandler
of UNUserNotificationCenter
delegate method
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
messagingManager?.appDidReceiveMessage(userInfo)
}
You need to check in didReceiveRemoteNotification
with fetchCompletionHandler
of UNUserNotificationCenter
delegate method
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
messagingManager?.appDidReceiveMessage(userInfo)
}
answered Nov 16 '18 at 7:14
iPareshiParesh
1,2451926
1,2451926
I updated the question. My delegate method is not called when app is in background mode and not connected to the debugger;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:17
Have you confirm delegate UNUserNotificationCenter.current().delegate = self inside application(_:didFinishLaunchingWithOptions:) method
– iParesh
Nov 16 '18 at 7:18
Yes, I can confirm;) That method is called when app is connected to the debugger, but doesnt work when not connected to the debugger. Why?
– Bartłomiej Semańczyk
Nov 16 '18 at 7:21
What makes the difference with that two methods?;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:33
add a comment |
I updated the question. My delegate method is not called when app is in background mode and not connected to the debugger;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:17
Have you confirm delegate UNUserNotificationCenter.current().delegate = self inside application(_:didFinishLaunchingWithOptions:) method
– iParesh
Nov 16 '18 at 7:18
Yes, I can confirm;) That method is called when app is connected to the debugger, but doesnt work when not connected to the debugger. Why?
– Bartłomiej Semańczyk
Nov 16 '18 at 7:21
What makes the difference with that two methods?;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:33
I updated the question. My delegate method is not called when app is in background mode and not connected to the debugger;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:17
I updated the question. My delegate method is not called when app is in background mode and not connected to the debugger;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:17
Have you confirm delegate UNUserNotificationCenter.current().delegate = self inside application(_:didFinishLaunchingWithOptions:) method
– iParesh
Nov 16 '18 at 7:18
Have you confirm delegate UNUserNotificationCenter.current().delegate = self inside application(_:didFinishLaunchingWithOptions:) method
– iParesh
Nov 16 '18 at 7:18
Yes, I can confirm;) That method is called when app is connected to the debugger, but doesnt work when not connected to the debugger. Why?
– Bartłomiej Semańczyk
Nov 16 '18 at 7:21
Yes, I can confirm;) That method is called when app is connected to the debugger, but doesnt work when not connected to the debugger. Why?
– Bartłomiej Semańczyk
Nov 16 '18 at 7:21
What makes the difference with that two methods?;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:33
What makes the difference with that two methods?;)
– Bartłomiej Semańczyk
Nov 16 '18 at 7:33
add a comment |
I found this post very helpful for managing notifications in the background, basically you have to use the call with completion handler.
didReceiveRemoteNotification when in background
add a comment |
I found this post very helpful for managing notifications in the background, basically you have to use the call with completion handler.
didReceiveRemoteNotification when in background
add a comment |
I found this post very helpful for managing notifications in the background, basically you have to use the call with completion handler.
didReceiveRemoteNotification when in background
I found this post very helpful for managing notifications in the background, basically you have to use the call with completion handler.
didReceiveRemoteNotification when in background
answered Nov 16 '18 at 16:51
MariaMaria
2,65411523
2,65411523
add a comment |
add a comment |
Your messagingManager
is an optional. You should check, that it isn't nil
. If it is nil
, the appDidReciveMessage()
function would not be triggered
It is not nil;) it works when app is connected to the debugger
– Bartłomiej Semańczyk
Nov 16 '18 at 7:07
Did you check also that it isnt nil when your App is in Background?
– Jonathan
Nov 16 '18 at 7:10
add a comment |
Your messagingManager
is an optional. You should check, that it isn't nil
. If it is nil
, the appDidReciveMessage()
function would not be triggered
It is not nil;) it works when app is connected to the debugger
– Bartłomiej Semańczyk
Nov 16 '18 at 7:07
Did you check also that it isnt nil when your App is in Background?
– Jonathan
Nov 16 '18 at 7:10
add a comment |
Your messagingManager
is an optional. You should check, that it isn't nil
. If it is nil
, the appDidReciveMessage()
function would not be triggered
Your messagingManager
is an optional. You should check, that it isn't nil
. If it is nil
, the appDidReciveMessage()
function would not be triggered
answered Nov 16 '18 at 7:04
JonathanJonathan
1
1
It is not nil;) it works when app is connected to the debugger
– Bartłomiej Semańczyk
Nov 16 '18 at 7:07
Did you check also that it isnt nil when your App is in Background?
– Jonathan
Nov 16 '18 at 7:10
add a comment |
It is not nil;) it works when app is connected to the debugger
– Bartłomiej Semańczyk
Nov 16 '18 at 7:07
Did you check also that it isnt nil when your App is in Background?
– Jonathan
Nov 16 '18 at 7:10
It is not nil;) it works when app is connected to the debugger
– Bartłomiej Semańczyk
Nov 16 '18 at 7:07
It is not nil;) it works when app is connected to the debugger
– Bartłomiej Semańczyk
Nov 16 '18 at 7:07
Did you check also that it isnt nil when your App is in Background?
– Jonathan
Nov 16 '18 at 7:10
Did you check also that it isnt nil when your App is in Background?
– Jonathan
Nov 16 '18 at 7:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332889%2fdidreceiveremotenotification-is-not-called-after-notification-arrives-and-app-i%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown