Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions ios/src/ZotMeet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// TODO: if we're using Firebase, uncomment next string
//FirebaseApp.configure()
FirebaseApp.configure()

// [START set_messaging_delegate]
Messaging.messaging().delegate = self
Expand All @@ -22,6 +21,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// [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(
Expand All @@ -46,8 +53,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("Message ID 1: \(messageID)")
}

// Print full message.
#if DEBUG
print("push userInfo 1:", userInfo)
#endif
sendPushToWebView(userInfo: userInfo)
}

Expand All @@ -62,8 +70,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("Message ID 2: \(messageID)")
}

// Print full message. **
#if DEBUG
print("push userInfo 2:", userInfo)
#endif
sendPushToWebView(userInfo: userInfo)

completionHandler(UIBackgroundFetchResult.newData)
Expand Down Expand Up @@ -100,8 +109,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("Message ID: 3 \(messageID)")
}

// Print full message.
#if DEBUG
print("push userInfo 3:", userInfo)
#endif
sendPushToWebView(userInfo: userInfo)

// Change this to your preferred presentation option
Expand All @@ -119,8 +129,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print full message.
#if DEBUG
print("push userInfo 4:", userInfo)
#endif
sendPushClickToWebView(userInfo: userInfo)

completionHandler()
Expand All @@ -131,7 +142,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
extension AppDelegate : MessagingDelegate {
// [START refresh_token]
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
#if DEBUG
print("Firebase registration token: \(String(describing: fcmToken))")
#endif

let dataDict:[String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
Expand Down
60 changes: 34 additions & 26 deletions ios/src/ZotMeet/PushNotifications.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import UIKit
import WebKit
import FirebaseMessaging

func registerForPushNotifications() {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}

class SubscribeMessage {
var topic = ""
var eventValue = ""
Expand Down Expand Up @@ -82,36 +89,34 @@ func returnPermissionState(state: String){

func handlePushPermission() {
UNUserNotificationCenter.current().getNotificationSettings () { settings in
switch settings.authorizationStatus {
case .notDetermined:
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { (success, error) in
if error == nil {
if success == true {
returnPermissionResult(isGranted: true)
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
else {
returnPermissionResult(isGranted: false)
}
}
else {
switch settings.authorizationStatus {
case .notDetermined:
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { (success, error) in
if error == nil {
if success == true {
registerForPushNotifications()
returnPermissionResult(isGranted: true)
} else {
returnPermissionResult(isGranted: false)
}
}
)
case .denied:
returnPermissionResult(isGranted: false)
case .authorized, .ephemeral, .provisional:
returnPermissionResult(isGranted: true)
@unknown default:
return;
}
else {
returnPermissionResult(isGranted: false)
}
}
)
case .denied:
returnPermissionResult(isGranted: false)
case .authorized, .ephemeral, .provisional:
registerForPushNotifications()
returnPermissionResult(isGranted: true)
@unknown default:
return;
}
}
}
func handlePushState() {
UNUserNotificationCenter.current().getNotificationSettings () { settings in
Expand All @@ -121,10 +126,13 @@ func handlePushState() {
case .denied:
returnPermissionState(state: "denied")
case .authorized:
registerForPushNotifications()
returnPermissionState(state: "authorized")
case .ephemeral:
registerForPushNotifications()
returnPermissionState(state: "ephemeral")
case .provisional:
registerForPushNotifications()
returnPermissionState(state: "provisional")
@unknown default:
returnPermissionState(state: "unknown")
Expand Down
3 changes: 0 additions & 3 deletions ios/src/ZotMeet/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ extension ViewController: WKScriptMessageHandler {
if message.name == "print" {
printView(webView: ZotMeet.webView)
}
if message.name == "push-subscribe" {
handleSubscribeTouch(message: message)
}
if message.name == "push-permission-request" {
handlePushPermission()
}
Expand Down
1 change: 0 additions & 1 deletion ios/src/ZotMeet/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func createWebView(container: UIView, WKSMH: WKScriptMessageHandler, WKND: WKNav
let userContentController = WKUserContentController()

userContentController.add(WKSMH, name: "print")
userContentController.add(WKSMH, name: "push-subscribe")
userContentController.add(WKSMH, name: "push-permission-request")
userContentController.add(WKSMH, name: "push-permission-state")
userContentController.add(WKSMH, name: "push-token")
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"date-fns": "^4.1.0",
"date-fns-tz": "^3.2.0",
"dotenv": "^16.4.5",
"firebase-admin": "^13.10.0",
"googleapis": "^148.0.0",
"lucide-react": "^0.453.0",
"next": "16.1.1",
Expand Down
Loading
Loading