-
Notifications
You must be signed in to change notification settings - Fork 6
chore: [SDK-4788] add local notification compatibility workaround #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8182096
fix(examples): add iOS delegate shim for OneSignal compatibility
fadi-george 35a3e8c
chore(examples): add OneSignal notification button
fadi-george c8dd9c0
fix(examples): handle remote push in delegate shim
fadi-george f8ab9aa
docs: [SDK-4788] clarify local notification workaround
fadi-george ee49195
style(examples): reformat long lines
fadi-george faf965e
fix: [SDK-4788] handle notification demo failures
fadi-george File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| # Default App ID (used when ONESIGNAL_APP_ID is empty or missing): 77e32082-ea27-42e3-a898-c72e141824ef | ||
| ONESIGNAL_APP_ID=your-onesignal-app-id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
examples/plugin-local-notif/Platforms/iOS/OneSignalCompatibleNotificationDelegate.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| using Foundation; | ||
| using Plugin.LocalNotification.Platforms; | ||
| using UserNotifications; | ||
|
|
||
| namespace PluginLocalNotifDemo; | ||
|
|
||
| public sealed class OneSignalCompatibleNotificationDelegate : UserNotificationCenterDelegate | ||
| { | ||
| // OneSignal's swizzle can exchange method implementations on this class, so | ||
| // depending on which slot iOS invokes, either the normal overrides or the | ||
| // onesignal-prefixed exports receive the callback. Both route remote pushes | ||
| // to foreground presentation and leave local notifications to the plugin. | ||
| public override void WillPresentNotification( | ||
| UNUserNotificationCenter center, | ||
| UNNotification notification, | ||
| Action<UNNotificationPresentationOptions> completionHandler | ||
| ) | ||
| { | ||
| if (HandledAsRemotePush(notification, completionHandler)) | ||
| return; | ||
|
|
||
| base.WillPresentNotification(center, notification, completionHandler); | ||
| } | ||
|
|
||
| public override void DidReceiveNotificationResponse( | ||
| UNUserNotificationCenter center, | ||
| UNNotificationResponse response, | ||
| Action completionHandler | ||
| ) | ||
| { | ||
| if (response.Notification.Request.Trigger is UNPushNotificationTrigger) | ||
| { | ||
| completionHandler(); | ||
| return; | ||
| } | ||
|
|
||
| base.DidReceiveNotificationResponse(center, response, completionHandler); | ||
| } | ||
|
|
||
| [Export("onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:")] | ||
| public void OneSignalWillPresentNotification( | ||
| UNUserNotificationCenter center, | ||
| UNNotification notification, | ||
| Action<UNNotificationPresentationOptions> completionHandler | ||
| ) | ||
| { | ||
| if (HandledAsRemotePush(notification, completionHandler)) | ||
| return; | ||
|
|
||
| base.WillPresentNotification(center, notification, completionHandler); | ||
| } | ||
|
|
||
| [Export( | ||
| "onesignalUserNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:" | ||
| )] | ||
| public void OneSignalDidReceiveNotificationResponse( | ||
| UNUserNotificationCenter center, | ||
| UNNotificationResponse response, | ||
| Action completionHandler | ||
| ) | ||
| { | ||
| if (response.Notification.Request.Trigger is UNPushNotificationTrigger) | ||
| { | ||
| completionHandler(); | ||
| return; | ||
| } | ||
|
|
||
| base.DidReceiveNotificationResponse(center, response, completionHandler); | ||
| } | ||
|
|
||
| private static bool HandledAsRemotePush( | ||
| UNNotification notification, | ||
| Action<UNNotificationPresentationOptions> completionHandler | ||
| ) | ||
| { | ||
| if (notification.Request.Trigger is not UNPushNotificationTrigger) | ||
| return false; | ||
|
|
||
| completionHandler( | ||
| UNNotificationPresentationOptions.Banner | ||
| | UNNotificationPresentationOptions.List | ||
| | UNNotificationPresentationOptions.Sound | ||
| | UNNotificationPresentationOptions.Badge | ||
| ); | ||
| return true; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.