ios push notifications

This commit is contained in:
Trey t
2025-11-13 16:13:36 -06:00
parent b2f2627ad5
commit ff390a85c2
5 changed files with 37 additions and 30 deletions

View File

@@ -9,7 +9,7 @@ package com.mycrib.shared.network
*/
object ApiConfig {
// ⚠️ CHANGE THIS TO TOGGLE ENVIRONMENT ⚠️
val CURRENT_ENV = Environment.LOCAL
val CURRENT_ENV = Environment.DEV
enum class Environment {
LOCAL,

View File

@@ -383,6 +383,8 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = iosApp/Info.plist;
INFOPLIST_KEY_NSCameraUsageDescription = "MyCrib needs access to your camera to take photos of completed tasks";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "MyCrib needs access to your photo library to select photos of completed tasks";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -650,6 +652,8 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = iosApp/Info.plist;
INFOPLIST_KEY_NSCameraUsageDescription = "MyCrib needs access to your camera to take photos of completed tasks";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "MyCrib needs access to your photo library to select photos of completed tasks";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;

View File

@@ -7,17 +7,17 @@
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.mycrib.app</string>
<key>CFBundleURLSchemes</key>
<array>
<string>mycrib</string>
</array>
<key>CFBundleURLName</key>
<string>com.mycrib.app</string>
</dict>
</array>
<key>NSCameraUsageDescription</key>
<string>MyCrib needs access to your camera to take photos of completed tasks</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>MyCrib needs access to your photo library to select photos of completed tasks</string>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
</dict>
</plist>

View File

@@ -63,7 +63,7 @@ class PushNotificationManager: NSObject, ObservableObject {
print("⚠️ No auth token available, will register device after login")
return
}
let request = DeviceRegistrationRequest(
registrationId: token,
platform: "ios"
@@ -93,10 +93,10 @@ class PushNotificationManager: NSObject, ObservableObject {
if let notificationId = userInfo["notification_id"] as? String {
print("Notification ID: \(notificationId)")
// // Mark as read when user taps notification
// Task {
// await markNotificationAsRead(notificationId: notificationId)
// }
// Mark as read when user taps notification
Task {
await markNotificationAsRead(notificationId: notificationId)
}
}
if let type = userInfo["type"] as? String {
@@ -130,24 +130,24 @@ class PushNotificationManager: NSObject, ObservableObject {
}
}
// private func markNotificationAsRead(notificationId: String) async {
// guard TokenStorage.shared.getToken() != nil,
// let notificationIdInt = Int32(notificationId) else {
// return
// }
//
// do {
// let result = try await APILayer.shared.markNotificationAsRead(notificationId: notificationIdInt)
//
// if result is ApiResultSuccess<Notification> {
// print(" Notification marked as read")
// } else if let error = result as? ApiResultError {
// print(" Failed to mark notification as read: \(error.message)")
// }
// } catch {
// print(" Error marking notification as read: \(error.localizedDescription)")
// }
// }
private func markNotificationAsRead(notificationId: String) async {
guard TokenStorage.shared.getToken() != nil,
let notificationIdInt = Int32(notificationId) else {
return
}
do {
let result = try await APILayer.shared.markNotificationAsRead(notificationId: notificationIdInt)
if result is ApiResultSuccess<ComposeApp.Notification> {
print("✅ Notification marked as read")
} else if let error = result as? ApiResultError {
print("❌ Failed to mark notification as read: \(error.message)")
}
} catch {
print("❌ Error marking notification as read: \(error.localizedDescription)")
}
}
// MARK: - Notification Preferences
@@ -206,3 +206,4 @@ class PushNotificationManager: NSObject, ObservableObject {
UIApplication.shared.applicationIconBadgeNumber = count
}
}

View File

@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.tt.mycrib.MyCrib</string>