dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

[iOS] Lifecycle for push notifications needs to be conditionally implemented #24237

Open Redth opened 1 month ago

Redth commented 1 month ago

Description

For .NET 9 Preview 7, we added iOSLifecycle.OnReceivedRemoteNotifications and iOSLifecycle.OnRegisteredForRemoteNotifications lifecycle events in #23452 (Yay!)

But we forgot to ensure that for cases when an app does not want these implemented, it needs to appear to Apple that it is not using them, otherwise I believe apps will be flagged in submission for not including the appropriate entitlements (need to fact check this).

I believe we could do this by overriding RespondsToSelector on the delegate and checking for these selectors and returning false if we have determined the app isn't actually wiring up the registration (need to fact check this).

We need to decide how we want to determine that. Maybe we can look at the entitlements at runtime and see if aps entitlement is declared? or we can set a flag when registering for the lifecycle event, however this may conflict with cases where someone manually overrides these methods on their delegate. We could also have a property on the delegate to toggle this on and off.

Version with bug

9.0.0-preview.7

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

9.0.0-preview.6

Affected platforms

iOS, macOS

Did you find any workaround?

For now, one could manually override RespondsToSelector and return false when these are queried if they do not want to appear to have them implemented.

Thanks @aritchie for noticing this change and helping flag the potential issues with it!

github-actions[bot] commented 1 month ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

mattleibow commented 1 month ago

There is also another warning in the console if you run about some other override. I forget exactly, so when I get to my mac I can update this issue.

aritchie commented 1 month ago

There is also another warning in the console if you run about some other override. I forget exactly, so when I get to my mac I can update this issue.

PerformFetch

For .NET 9 Preview 7, we added iOSLifecycle.OnReceivedRemoteNotifications and iOSLifecycle.OnRegisteredForRemoteNotifications lifecycle events in https://github.com/dotnet/maui/pull/23452 (Yay!)

You're missing:

  [Export("application:didFailToRegisterForRemoteNotificationsWithError:")]
  public void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
Redth commented 1 month ago

Ok, sounds like responds to selector will not be enough, and that the static analysis apple does is going to flag the inclusion of it. We may need to revert these changes for now.

aritchie commented 1 month ago

Apple doesn't care about the PerformFetch as much since it is deprecated, but they will not be happy with push hooks if they aren't actually being used. I've been trying to solve this one for a while, but just gave up and document the fact that you have to hook these methods manually