Showing
5 changed files
with
99 additions
and
0 deletions
| @@ -393,6 +393,11 @@ interface PlatformHostApi { | @@ -393,6 +393,11 @@ interface PlatformHostApi { | ||
| 393 | fun getFullUserAgent(): String | 393 | fun getFullUserAgent(): String |
| 394 | /** 是否是中国大陆地区 */ | 394 | /** 是否是中国大陆地区 */ |
| 395 | fun isChinaRegion(callback: (Result<Boolean>) -> Unit) | 395 | fun isChinaRegion(callback: (Result<Boolean>) -> Unit) |
| 396 | + /** | ||
| 397 | + * 获取是否开启了通知权限 | ||
| 398 | + * -1: 已拒绝, 0:需要请求权限, 1:已授权 | ||
| 399 | + */ | ||
| 400 | + fun getApnsAuthStatus(callback: (Result<Long>) -> Unit) | ||
| 396 | /** 申请通知权限 */ | 401 | /** 申请通知权限 */ |
| 397 | fun requestNotificationAuth(callback: (Result<Boolean>) -> Unit) | 402 | fun requestNotificationAuth(callback: (Result<Boolean>) -> Unit) |
| 398 | /** 是否是测试环境 */ | 403 | /** 是否是测试环境 */ |
| @@ -500,6 +505,24 @@ interface PlatformHostApi { | @@ -500,6 +505,24 @@ interface PlatformHostApi { | ||
| 500 | } | 505 | } |
| 501 | } | 506 | } |
| 502 | run { | 507 | run { |
| 508 | + val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.getApnsAuthStatus$separatedMessageChannelSuffix", codec) | ||
| 509 | + if (api != null) { | ||
| 510 | + channel.setMessageHandler { _, reply -> | ||
| 511 | + api.getApnsAuthStatus{ result: Result<Long> -> | ||
| 512 | + val error = result.exceptionOrNull() | ||
| 513 | + if (error != null) { | ||
| 514 | + reply.reply(PlatformApiPigeonUtils.wrapError(error)) | ||
| 515 | + } else { | ||
| 516 | + val data = result.getOrNull() | ||
| 517 | + reply.reply(PlatformApiPigeonUtils.wrapResult(data)) | ||
| 518 | + } | ||
| 519 | + } | ||
| 520 | + } | ||
| 521 | + } else { | ||
| 522 | + channel.setMessageHandler(null) | ||
| 523 | + } | ||
| 524 | + } | ||
| 525 | + run { | ||
| 503 | val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth$separatedMessageChannelSuffix", codec) | 526 | val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth$separatedMessageChannelSuffix", codec) |
| 504 | if (api != null) { | 527 | if (api != null) { |
| 505 | channel.setMessageHandler { _, reply -> | 528 | channel.setMessageHandler { _, reply -> |
| @@ -421,6 +421,9 @@ protocol PlatformHostApi { | @@ -421,6 +421,9 @@ protocol PlatformHostApi { | ||
| 421 | func getFullUserAgent() throws -> String | 421 | func getFullUserAgent() throws -> String |
| 422 | /// 是否是中国大陆地区 | 422 | /// 是否是中国大陆地区 |
| 423 | func isChinaRegion(completion: @escaping (Result<Bool, Error>) -> Void) | 423 | func isChinaRegion(completion: @escaping (Result<Bool, Error>) -> Void) |
| 424 | + /// 获取是否开启了通知权限 | ||
| 425 | + /// -1: 已拒绝, 0:需要请求权限, 1:已授权 | ||
| 426 | + func getApnsAuthStatus(completion: @escaping (Result<Int64, Error>) -> Void) | ||
| 424 | /// 申请通知权限 | 427 | /// 申请通知权限 |
| 425 | func requestNotificationAuth(completion: @escaping (Result<Bool, Error>) -> Void) | 428 | func requestNotificationAuth(completion: @escaping (Result<Bool, Error>) -> Void) |
| 426 | /// 是否是测试环境 | 429 | /// 是否是测试环境 |
| @@ -511,6 +514,23 @@ class PlatformHostApiSetup { | @@ -511,6 +514,23 @@ class PlatformHostApiSetup { | ||
| 511 | } else { | 514 | } else { |
| 512 | isChinaRegionChannel.setMessageHandler(nil) | 515 | isChinaRegionChannel.setMessageHandler(nil) |
| 513 | } | 516 | } |
| 517 | + /// 获取是否开启了通知权限 | ||
| 518 | + /// -1: 已拒绝, 0:需要请求权限, 1:已授权 | ||
| 519 | + let getApnsAuthStatusChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.getApnsAuthStatus\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) | ||
| 520 | + if let api = api { | ||
| 521 | + getApnsAuthStatusChannel.setMessageHandler { _, reply in | ||
| 522 | + api.getApnsAuthStatus { result in | ||
| 523 | + switch result { | ||
| 524 | + case .success(let res): | ||
| 525 | + reply(wrapResult(res)) | ||
| 526 | + case .failure(let error): | ||
| 527 | + reply(wrapError(error)) | ||
| 528 | + } | ||
| 529 | + } | ||
| 530 | + } | ||
| 531 | + } else { | ||
| 532 | + getApnsAuthStatusChannel.setMessageHandler(nil) | ||
| 533 | + } | ||
| 514 | /// 申请通知权限 | 534 | /// 申请通知权限 |
| 515 | let requestNotificationAuthChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) | 535 | let requestNotificationAuthChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) |
| 516 | if let api = api { | 536 | if let api = api { |
| @@ -49,6 +49,7 @@ extension WatchAppOtherInfo{ | @@ -49,6 +49,7 @@ extension WatchAppOtherInfo{ | ||
| 49 | * `{systemWebViewUA} doublefeel/{versionCode}({versionName})(Apple##Apple##{model}; iOS{osVersion}; {height}x{width})(huawei)` | 49 | * `{systemWebViewUA} doublefeel/{versionCode}({versionName})(Apple##Apple##{model}; iOS{osVersion}; {height}x{width})(huawei)` |
| 50 | */ | 50 | */ |
| 51 | final class PlatformHostApiImpl: NSObject, PlatformHostApi { | 51 | final class PlatformHostApiImpl: NSObject, PlatformHostApi { |
| 52 | + | ||
| 52 | private var sendEmailCompletion: ((Result<Bool, any Error>) -> Void)? | 53 | private var sendEmailCompletion: ((Result<Bool, any Error>) -> Void)? |
| 53 | 54 | ||
| 54 | func isDebugEnvoriment() throws -> Bool { | 55 | func isDebugEnvoriment() throws -> Bool { |
| @@ -66,6 +67,26 @@ final class PlatformHostApiImpl: NSObject, PlatformHostApi { | @@ -66,6 +67,26 @@ final class PlatformHostApiImpl: NSObject, PlatformHostApi { | ||
| 66 | completion(.success(isChinaMainLand)) | 67 | completion(.success(isChinaMainLand)) |
| 67 | } | 68 | } |
| 68 | } | 69 | } |
| 70 | + /// 检查 APNs 通知授权状态:-1 已拒绝,0 需要请求,1 已授权。 | ||
| 71 | + func getApnsAuthStatus(completion: @escaping (Result<Int64, any Error>) -> Void) { | ||
| 72 | + Task { | ||
| 73 | + let settings = await UNUserNotificationCenter.current().notificationSettings() | ||
| 74 | + let status: Int64 | ||
| 75 | + | ||
| 76 | + switch settings.authorizationStatus { | ||
| 77 | + case .authorized, .provisional, .ephemeral: | ||
| 78 | + status = 1 | ||
| 79 | + case .denied: | ||
| 80 | + status = -1 | ||
| 81 | + case .notDetermined: | ||
| 82 | + status = 0 | ||
| 83 | + @unknown default: | ||
| 84 | + status = 0 | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + completion(.success(status)) | ||
| 88 | + } | ||
| 89 | + } | ||
| 69 | 90 | ||
| 70 | func requestNotificationAuth(completion: @escaping (Result<Bool, any Error>) -> Void) { | 91 | func requestNotificationAuth(completion: @escaping (Result<Bool, any Error>) -> Void) { |
| 71 | Task { | 92 | Task { |
| @@ -494,6 +494,36 @@ class PlatformHostApi { | @@ -494,6 +494,36 @@ class PlatformHostApi { | ||
| 494 | } | 494 | } |
| 495 | } | 495 | } |
| 496 | 496 | ||
| 497 | + /// 获取是否开启了通知权限 | ||
| 498 | + /// -1: 已拒绝, 0:需要请求权限, 1:已授权 | ||
| 499 | + Future<int> getApnsAuthStatus() async { | ||
| 500 | + final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.getApnsAuthStatus$pigeonVar_messageChannelSuffix'; | ||
| 501 | + final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>( | ||
| 502 | + pigeonVar_channelName, | ||
| 503 | + pigeonChannelCodec, | ||
| 504 | + binaryMessenger: pigeonVar_binaryMessenger, | ||
| 505 | + ); | ||
| 506 | + final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null); | ||
| 507 | + final List<Object?>? pigeonVar_replyList = | ||
| 508 | + await pigeonVar_sendFuture as List<Object?>?; | ||
| 509 | + if (pigeonVar_replyList == null) { | ||
| 510 | + throw _createConnectionError(pigeonVar_channelName); | ||
| 511 | + } else if (pigeonVar_replyList.length > 1) { | ||
| 512 | + throw PlatformException( | ||
| 513 | + code: pigeonVar_replyList[0]! as String, | ||
| 514 | + message: pigeonVar_replyList[1] as String?, | ||
| 515 | + details: pigeonVar_replyList[2], | ||
| 516 | + ); | ||
| 517 | + } else if (pigeonVar_replyList[0] == null) { | ||
| 518 | + throw PlatformException( | ||
| 519 | + code: 'null-error', | ||
| 520 | + message: 'Host platform returned null value for non-null return value.', | ||
| 521 | + ); | ||
| 522 | + } else { | ||
| 523 | + return (pigeonVar_replyList[0] as int?)!; | ||
| 524 | + } | ||
| 525 | + } | ||
| 526 | + | ||
| 497 | /// 申请通知权限 | 527 | /// 申请通知权限 |
| 498 | Future<bool> requestNotificationAuth() async { | 528 | Future<bool> requestNotificationAuth() async { |
| 499 | final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth$pigeonVar_messageChannelSuffix'; | 529 | final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth$pigeonVar_messageChannelSuffix'; |
| @@ -140,6 +140,11 @@ abstract class PlatformHostApi { | @@ -140,6 +140,11 @@ abstract class PlatformHostApi { | ||
| 140 | @async | 140 | @async |
| 141 | bool isChinaRegion(); | 141 | bool isChinaRegion(); |
| 142 | 142 | ||
| 143 | + /// 获取是否开启了通知权限 | ||
| 144 | + /// -1: 已拒绝, 0:需要请求权限, 1:已授权 | ||
| 145 | + @async | ||
| 146 | + int getApnsAuthStatus(); | ||
| 147 | + | ||
| 143 | /// 申请通知权限 | 148 | /// 申请通知权限 |
| 144 | @async | 149 | @async |
| 145 | bool requestNotificationAuth(); | 150 | bool requestNotificationAuth(); |
-
Please register or login to post a comment