-
Notifications
You must be signed in to change notification settings - Fork 1
feat: ✨ ios notifications #554
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
Open
ethancha0
wants to merge
8
commits into
main
Choose a base branch
from
ewc-ios-notifications
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b23027e
feat: ✨ ios notifications
ethancha0 2e80cf1
feat: ✨ push notif setting
ethancha0 cad10ba
fix: 🐛 cubic
ethancha0 96b6de5
fix: 🐛 rm web push notif system
ethancha0 e945943
fix: 🐛 cleanup
ethancha0 5ac9f60
fix: 🐛 edge cases
ethancha0 7e546d3
feat: ✨ switch firebase to aws sns
ethancha0 567061f
chore: 🔧 rm dead firebase code
ethancha0 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,143 +1,62 @@ | ||
| import UIKit | ||
| import FirebaseCore | ||
| import FirebaseMessaging | ||
|
|
||
|
|
||
| @UIApplicationMain | ||
| class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
|
||
| var window : UIWindow? | ||
|
|
||
| func application(_ application: UIApplication, | ||
| didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
|
|
||
| // TODO: if we're using Firebase, uncomment next string | ||
| //FirebaseApp.configure() | ||
|
|
||
| // [START set_messaging_delegate] | ||
| Messaging.messaging().delegate = self | ||
| // [END set_messaging_delegate] | ||
| // Register for remote notifications. This shows a permission dialog on first run, to | ||
| // show the dialog at a more appropriate time move this registration accordingly. | ||
| // [START register_for_notifications] | ||
|
|
||
| UNUserNotificationCenter.current().delegate = self | ||
| UNUserNotificationCenter.current().getNotificationSettings { settings in | ||
| switch settings.authorizationStatus { | ||
| case .authorized, .ephemeral, .provisional: | ||
| registerForPushNotifications() | ||
| default: | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] | ||
| // UNUserNotificationCenter.current().requestAuthorization( | ||
| // options: authOptions, | ||
| // completionHandler: {_, _ in }) | ||
|
|
||
| // TODO: if we're using Firebase, uncomment next string | ||
| // application.registerForRemoteNotifications() | ||
|
|
||
| // [END register_for_notifications] | ||
| return true | ||
| } | ||
|
|
||
| // [START receive_message] | ||
| func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { | ||
| // If you are receiving a notification message while your app is in the background, | ||
| // this callback will not be fired till the user taps on the notification launching the application. | ||
| // With swizzling disabled you must let Messaging know about the message, for Analytics | ||
| // Messaging.messaging().appDidReceiveMessage(userInfo) | ||
| // Print message ID. | ||
| if let messageID = userInfo[gcmMessageIDKey] { | ||
| print("Message ID 1: \(messageID)") | ||
| } | ||
|
|
||
| // Print full message. | ||
| print("push userInfo 1:", userInfo) | ||
| sendPushToWebView(userInfo: userInfo) | ||
| } | ||
|
|
||
| func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], | ||
| fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { | ||
| // If you are receiving a notification message while your app is in the background, | ||
| // this callback will not be fired till the user taps on the notification launching the application. | ||
| // With swizzling disabled you must let Messaging know about the message, for Analytics | ||
| // Messaging.messaging().appDidReceiveMessage(userInfo) | ||
| // Print message ID. | ||
| if let messageID = userInfo[gcmMessageIDKey] { | ||
| print("Message ID 2: \(messageID)") | ||
| } | ||
|
|
||
| // Print full message. ** | ||
| print("push userInfo 2:", userInfo) | ||
| sendPushToWebView(userInfo: userInfo) | ||
|
|
||
| completionHandler(UIBackgroundFetchResult.newData) | ||
| } | ||
|
|
||
| // [END receive_message] | ||
| func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { | ||
| print("Unable to register for remote notifications: \(error.localizedDescription)") | ||
| } | ||
|
|
||
| // This function is added here only for debugging purposes, and can be removed if swizzling is enabled. | ||
| // If swizzling is disabled then this function must be implemented so that the APNs token can be paired to | ||
| // the FCM registration token. | ||
| // func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | ||
| // print("APNs token retrieved: \(deviceToken)") | ||
| // | ||
| // // With swizzling disabled you must set the APNs token here. | ||
| // // Messaging.messaging().apnsToken = deviceToken | ||
| // } | ||
| func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | ||
| let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined() | ||
| setApnsDeviceTokenHex(token) | ||
| sendApnsTokenToWebView(token: token) | ||
| } | ||
| } | ||
|
|
||
| // [START ios_10_message_handling] | ||
| extension AppDelegate : UNUserNotificationCenterDelegate { | ||
|
|
||
| func userNotificationCenter(_ center: UNUserNotificationCenter, | ||
| willPresent notification: UNNotification, | ||
| withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { | ||
| let userInfo = notification.request.content.userInfo | ||
|
|
||
| // With swizzling disabled you must let Messaging know about the message, for Analytics | ||
| // Messaging.messaging().appDidReceiveMessage(userInfo) | ||
| // Print message ID. | ||
| if let messageID = userInfo[gcmMessageIDKey] { | ||
| print("Message ID: 3 \(messageID)") | ||
| } | ||
|
|
||
| // Print full message. | ||
| print("push userInfo 3:", userInfo) | ||
| sendPushToWebView(userInfo: userInfo) | ||
|
|
||
| // Change this to your preferred presentation option | ||
| completionHandler([[.banner, .list, .sound]]) | ||
| } | ||
|
|
||
| func userNotificationCenter(_ center: UNUserNotificationCenter, | ||
| didReceive response: UNNotificationResponse, | ||
| withCompletionHandler completionHandler: @escaping () -> Void) { | ||
| let userInfo = response.notification.request.content.userInfo | ||
| // Print message ID. | ||
| if let messageID = userInfo[gcmMessageIDKey] { | ||
| print("Message ID 4: \(messageID)") | ||
| } | ||
|
|
||
| // With swizzling disabled you must let Messaging know about the message, for Analytics | ||
| // Messaging.messaging().appDidReceiveMessage(userInfo) | ||
| // Print full message. | ||
| print("push userInfo 4:", userInfo) | ||
| sendPushClickToWebView(userInfo: userInfo) | ||
|
|
||
| completionHandler() | ||
| } | ||
| } | ||
| // [END ios_10_message_handling] | ||
|
|
||
| extension AppDelegate : MessagingDelegate { | ||
| // [START refresh_token] | ||
| func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { | ||
| print("Firebase registration token: \(String(describing: fcmToken))") | ||
|
|
||
| let dataDict:[String: String] = ["token": fcmToken ?? ""] | ||
| NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict) | ||
| handleFCMToken() | ||
| // TODO: If necessary send token to application server. | ||
| // Note: This callback is fired at each app startup and whenever a new token is generated. | ||
| } | ||
| // [END refresh_token] | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Use the existing
apnsTokenHexString(from:)helper instead of duplicating APNs token formatting logic.Prompt for AI agents