Showing
1 changed file
with
29 additions
and
0 deletions
| @@ -54,6 +54,35 @@ final class PlatformHostApiImpl: PlatformHostApi { | @@ -54,6 +54,35 @@ final class PlatformHostApiImpl: PlatformHostApi { | ||
| 54 | return false | 54 | return false |
| 55 | #endif | 55 | #endif |
| 56 | } | 56 | } |
| 57 | + | ||
| 58 | + func requestNotificationAuth(completion: @escaping (Result<Bool, any Error>) -> Void) { | ||
| 59 | + Task { | ||
| 60 | + let center = UNUserNotificationCenter.current() | ||
| 61 | + let settings = await center.notificationSettings() | ||
| 62 | + | ||
| 63 | + switch settings.authorizationStatus { | ||
| 64 | + case .authorized, .provisional, .ephemeral: | ||
| 65 | + completion(.success(true)) | ||
| 66 | + case .notDetermined: | ||
| 67 | + do { | ||
| 68 | + let granted = try await center.requestAuthorization(options: [.alert, .sound, .badge]) | ||
| 69 | + if granted { | ||
| 70 | + await MainActor.run { | ||
| 71 | + UIApplication.shared.registerForRemoteNotifications() | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + completion(.success(granted)) | ||
| 75 | + } catch { | ||
| 76 | + completion(.failure(error)) | ||
| 77 | + } | ||
| 78 | + case .denied: | ||
| 79 | + completion(.success(false)) | ||
| 80 | + @unknown default: | ||
| 81 | + completion(.success(false)) | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 57 | 86 | ||
| 58 | func nativeHandleUrl(urlString: String) throws -> Bool { | 87 | func nativeHandleUrl(urlString: String) throws -> Bool { |
| 59 | if let url = URL(string: urlString){ | 88 | if let url = URL(string: urlString){ |
-
Please register or login to post a comment