Push Notifications · Notification Service Extension | raywenderlich.com

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1258151-push-notifications/lessons/12

Notification Service Extension not working :o

  1. Took ending of Action Category lecture
  2. Added notification service extension manually
  3. modified sendEncrypted.php and ran php sendEncrypted.php in terminal

Payload should be by default modified with [modified] appended to title, but didn’t happen :o

Before making this post, ensured payload is

$payload = [
‘encrypted’ => true,
‘aps’ => [
‘alert’ => [
‘title’ => str_rot13(‘Otter Spotted’),
‘body’ => str_rot13(‘Come and see!’)
‘badge’ => 1,
‘mutable-content’ => 1,
‘sound’ => ‘default’,
“media-url” => str_rot13(‘https://koenig-media.raywenderlich.com/uploads/2018/11/otter-badge-RW-250x250.png’)

The notification comes through but isn’t modified.

Additionally, tried the ending files from download materials, but has additional code for badges, media attachments etc. Apart from that, unable to run that code since it gives some error after changing bundle ID. And as a different developer account, am forced to change bundle ID anyway.

Also, looking at the next lecture, I was unable to see the process to debug in Xcode

Screenshot 2020-01-29 at 5.02.55 PM

Also, I see these errors when I try to run the project from downloaded files, despite modifying the bundle ID.

Now, if I change “App Groups”, the project works fine. However when I add notification service extension, an App Group is not created automatically. Has something changed for more recent version of Xcode?

do you mean the title and body are encrypted? The correct result is that you see “Otter Spotted” and “Come and see!”

you sent the payload and it still doesn’t appear in the list? according to my script:

If you aren’t able to find your process listed, you might have to restart Xcode and/or your Mac, and maybe even restart your iPhone

setting up the app group is in the Badging the app icon video: your bundle ID prefixed by “group”

even if Xcode creates an app group for your extension, you don’t want to use it. You want to use the same app group as your main target.

Hi Audrey, let me clear this one by one.
Ignore the app groups part. I reached badging the app icon video and realised that’s something which needs to be done later.

If you aren’t able to find your process listed, you might have to restart Xcode and/or your Mac, and maybe even restart your iPhone

  • Did that. Even then, unable to find it in list. But that’s not even the main problem. Because that notification service extension isn’t working at all!
    Let me explain.

You take an app, say download ending app from ‘Action Categories’
You go to File > New > Target > Notification Service Extension > Name it, Hit finish and click cancel for scheme (according to script)
Once that’s done, any notification with valid alert title and body, with key ‘mutable-content’ in apes should be modified by function
didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)

By default, that function adds [modified] at the end of the notification title. But it isn’t doing that for my example. What am I missing? I did rewatch the video a few times, but I am just unable to get it working. I suspect something changed with latest Xcode version?

Let me make it simpler - Attached my copy of the same app, in which I followed through the tutorial till Action Categories
Then, File > New > Target > Notification Service Extension > Name it, Hit finish
Sent myself a notification with valid alert title and body, with value for key “mutable-content” set to 1
OtterSpotter.zip (1.6 MB)

Now the Notification Service Extension has default methods, hence it won’t be able to decrypt or do fancy stuff. However, it should add [Modified] at the end of alert title, like it did for you - http://prntscr.com/qumsju but in my case, it isn’t.

In short the notification service extension isn’t being used at all, hence doesn’t show up in the processes either.
Also meaning I am not able to proceed. Please let me know if I missed something.

it’s a total mystery! I took the beginning project, which is the same as the Action Categories finished project. I added the service target, updated the deployment target to match my phone, ran the app on my phone, edited the php file with my details, ran the php file, and it works as it should.

Your project contains two folders: Payload Modifier, which is listed as the target, and Payload Modification, but I don’t see why that should break anything.

You didn’t update the deployment target to iOS 13, so does that mean your phone is still on iOS 12? But when you added the service extension, that defaulted to iOS 13.2. Try changing it to match your phone. Although I would’ve thought Xcode would prevent you from installing anything 13.2 if your iOS is lower…

Good to know, so there are no additional steps…

Yeah, I tried adding Notification Service Extension twice, once Payload Modifier and once Payload modification - One with scheme cancelled and one with scheme enabled, just to ensure that notifications work and scheme has nothing to do with it!

Hi @Audrey, got it!
NSE had deployment target as 13.2 while my devices were in 13.1, that was the issue!

Got it, thanks. Took some time to decipher that, lol. Thanks for the assistance :slight_smile:

Leaving this here in case others stumble across the same doubt.

Mine (iOS12) didn’t working either. So, I need to update to iOS 13 in order to get the right message?

I think you just need to make sure all the targets are set to match your phone’s iOS version. Xcode defaults to the newest when you create the extension.