Commit 717b5e84bfedd8d5cec5af216f27dfc021c87165

Authored by 权海
1 parent eb78c200

feat(ui):添加apns状态查询接口

... ... @@ -393,6 +393,11 @@ interface PlatformHostApi {
fun getFullUserAgent(): String
/** 是否是中国大陆地区 */
fun isChinaRegion(callback: (Result<Boolean>) -> Unit)
/**
* 获取是否开启了通知权限
* -1: 已拒绝, 0:需要请求权限, 1:已授权
*/
fun getApnsAuthStatus(callback: (Result<Long>) -> Unit)
/** 申请通知权限 */
fun requestNotificationAuth(callback: (Result<Boolean>) -> Unit)
/** 是否是测试环境 */
... ... @@ -500,6 +505,24 @@ interface PlatformHostApi {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.getApnsAuthStatus$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
api.getApnsAuthStatus{ result: Result<Long> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(PlatformApiPigeonUtils.wrapError(error))
} else {
val data = result.getOrNull()
reply.reply(PlatformApiPigeonUtils.wrapResult(data))
}
}
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
... ...
... ... @@ -421,6 +421,9 @@ protocol PlatformHostApi {
func getFullUserAgent() throws -> String
/// 是否是中国大陆地区
func isChinaRegion(completion: @escaping (Result<Bool, Error>) -> Void)
/// 获取是否开启了通知权限
/// -1: 已拒绝, 0:需要请求权限, 1:已授权
func getApnsAuthStatus(completion: @escaping (Result<Int64, Error>) -> Void)
/// 申请通知权限
func requestNotificationAuth(completion: @escaping (Result<Bool, Error>) -> Void)
/// 是否是测试环境
... ... @@ -511,6 +514,23 @@ class PlatformHostApiSetup {
} else {
isChinaRegionChannel.setMessageHandler(nil)
}
/// 获取是否开启了通知权限
/// -1: 已拒绝, 0:需要请求权限, 1:已授权
let getApnsAuthStatusChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.getApnsAuthStatus\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
getApnsAuthStatusChannel.setMessageHandler { _, reply in
api.getApnsAuthStatus { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
getApnsAuthStatusChannel.setMessageHandler(nil)
}
/// 申请通知权限
let requestNotificationAuthChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
... ...
... ... @@ -49,6 +49,7 @@ extension WatchAppOtherInfo{
* `{systemWebViewUA} doublefeel/{versionCode}({versionName})(Apple##Apple##{model}; iOS{osVersion}; {height}x{width})(huawei)`
*/
final class PlatformHostApiImpl: NSObject, PlatformHostApi {
private var sendEmailCompletion: ((Result<Bool, any Error>) -> Void)?
func isDebugEnvoriment() throws -> Bool {
... ... @@ -66,6 +67,26 @@ final class PlatformHostApiImpl: NSObject, PlatformHostApi {
completion(.success(isChinaMainLand))
}
}
/// 检查 APNs 通知授权状态:-1 已拒绝,0 需要请求,1 已授权。
func getApnsAuthStatus(completion: @escaping (Result<Int64, any Error>) -> Void) {
Task {
let settings = await UNUserNotificationCenter.current().notificationSettings()
let status: Int64
switch settings.authorizationStatus {
case .authorized, .provisional, .ephemeral:
status = 1
case .denied:
status = -1
case .notDetermined:
status = 0
@unknown default:
status = 0
}
completion(.success(status))
}
}
func requestNotificationAuth(completion: @escaping (Result<Bool, any Error>) -> Void) {
Task {
... ...
... ... @@ -494,6 +494,36 @@ class PlatformHostApi {
}
}
/// 获取是否开启了通知权限
/// -1: 已拒绝, 0:需要请求权限, 1:已授权
Future<int> getApnsAuthStatus() async {
final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.getApnsAuthStatus$pigeonVar_messageChannelSuffix';
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
final List<Object?>? pigeonVar_replyList =
await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else if (pigeonVar_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (pigeonVar_replyList[0] as int?)!;
}
}
/// 申请通知权限
Future<bool> requestNotificationAuth() async {
final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestNotificationAuth$pigeonVar_messageChannelSuffix';
... ...
... ... @@ -140,6 +140,11 @@ abstract class PlatformHostApi {
@async
bool isChinaRegion();
/// 获取是否开启了通知权限
/// -1: 已拒绝, 0:需要请求权限, 1:已授权
@async
int getApnsAuthStatus();
/// 申请通知权限
@async
bool requestNotificationAuth();
... ...