Remote Notifications not working

The documentation for how to register for remote notifications includes the following text:

  1. Enable Remote Notifications for your project by clicking on iOS under Build Settings in the IDE navigator then clicking on the advanced tab in the Inspector then clicking the switch next to Remote Notifications.

I’m not seeing that option. Do I just use “push notifications”.

I have added the NotificationCenter singleton to my project but when I try to do anything with it I get an exception “Notifications were not added to this project.”

I’m sure I’m just missing something obvious.
Help?

Yup. The docs should say Push Notifications.

Have you tried the example projects?

I did Greg.

Those work, but if I try to register for remote notification I get that error.

I’m still a bit confused about that workflow. I see the web app example, but I’m not seeing an example on the iOS side.

Ok, so you need to check the Push Notifications capability in the iOS project, but also in the Apple Developer Portal for that app.

When you call the NotificationCenter.RequestAuthorization method, if the user allows notifications, the AuthorizationSucceeded event will fire with an object telling you what the user allows. You should call this method each time the app starts up from then on and look at the results because users can change their notification preferences at any time and you may want to deal with things differently.

Next, you’ll want to call NotificationCenter.RegisterForRemoteNotifications to request a token for that particular device. RemoteRegistrationSucceeded will fire if a token was provided. Again, you’ll want to call this each time the app launches because while it probably won’t change, Apple says that it may change. Store that token on your server with an identifier for this device or user’s account.

Once those things have been done, you can use the Xojo Cloud web framework stuff to send a notification to that particular device using the provided token. It will raise the NotificationReceived event to which you’ll either want to process it locally and not show it or return MobileNotifications.PresentationModes.All to allow the system to show the notification anyway.

Here’s a sample project that I gave to another user that has the setup code for remote notifications in it.

Oh, and I should mention that you’ll also need to go to your apple developer account and register for an Apple Push Notifications service (APNs) Key, which will provide you with the Key ID and certificate that you need to be able to send notifications.

Thanks Greg,

I had the APN in place.
I’ll step through this and your example this evening.

I think it’s something else, Greg.
I build a new empty project, drop the Notification Center in and register for remote notification in the app.opening event, and it’s fine.
I do the same in my (more elaborate) project and I get the previously mentioned error.
This is also the same project that won’t update the build number unless I restart Xojo.

Do me a favor and check your project to make sure there isn’t another object called NotificationCenter. I can see how that might cause a problem.

Beyond that I may need to see your project to get this fixed.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.