PlatformApi.swift
33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
// // Copyright 2013 The Flutter Authors. All rights reserved.
// Autogenerated from Pigeon (v25.5.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
import Foundation
#if os(iOS)
import Flutter
#elseif os(macOS)
import FlutterMacOS
#else
#error("Unsupported platform.")
#endif
private func wrapResult(_ result: Any?) -> [Any?] {
return [result]
}
private func wrapError(_ error: Any) -> [Any?] {
if let pigeonError = error as? PigeonError {
return [
pigeonError.code,
pigeonError.message,
pigeonError.details,
]
}
if let flutterError = error as? FlutterError {
return [
flutterError.code,
flutterError.message,
flutterError.details,
]
}
return [
"\(error)",
"\(type(of: error))",
"Stacktrace: \(Thread.callStackSymbols)",
]
}
private func isNullish(_ value: Any?) -> Bool {
return value is NSNull || value == nil
}
private func nilOrValue<T>(_ value: Any?) -> T? {
if value is NSNull { return nil }
return value as! T?
}
func deepEqualsPlatformApi(_ lhs: Any?, _ rhs: Any?) -> Bool {
let cleanLhs = nilOrValue(lhs) as Any?
let cleanRhs = nilOrValue(rhs) as Any?
switch (cleanLhs, cleanRhs) {
case (nil, nil):
return true
case (nil, _), (_, nil):
return false
case is (Void, Void):
return true
case let (cleanLhsHashable, cleanRhsHashable) as (AnyHashable, AnyHashable):
return cleanLhsHashable == cleanRhsHashable
case let (cleanLhsArray, cleanRhsArray) as ([Any?], [Any?]):
guard cleanLhsArray.count == cleanRhsArray.count else { return false }
for (index, element) in cleanLhsArray.enumerated() {
if !deepEqualsPlatformApi(element, cleanRhsArray[index]) {
return false
}
}
return true
case let (cleanLhsDictionary, cleanRhsDictionary) as ([AnyHashable: Any?], [AnyHashable: Any?]):
guard cleanLhsDictionary.count == cleanRhsDictionary.count else { return false }
for (key, cleanLhsValue) in cleanLhsDictionary {
guard cleanRhsDictionary.index(forKey: key) != nil else { return false }
if !deepEqualsPlatformApi(cleanLhsValue, cleanRhsDictionary[key]!) {
return false
}
}
return true
default:
// Any other type shouldn't be able to be used with pigeon. File an issue if you find this to be untrue.
return false
}
}
func deepHashPlatformApi(value: Any?, hasher: inout Hasher) {
if let valueList = value as? [AnyHashable] {
for item in valueList { deepHashPlatformApi(value: item, hasher: &hasher) }
return
}
if let valueDict = value as? [AnyHashable: AnyHashable] {
for key in valueDict.keys {
hasher.combine(key)
deepHashPlatformApi(value: valueDict[key]!, hasher: &hasher)
}
return
}
if let hashableValue = value as? AnyHashable {
hasher.combine(hashableValue.hashValue)
}
return hasher.combine(String(describing: value))
}
enum HResourceType: Int {
case image = 0
case video = 1
}
/// Generated class from Pigeon that represents data sent in messages.
struct AppleSignInModel: Hashable {
var userId: String
var email: String? = nil
var nickname: String? = nil
var identityToken: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> AppleSignInModel? {
let userId = pigeonVar_list[0] as! String
let email: String? = nilOrValue(pigeonVar_list[1])
let nickname: String? = nilOrValue(pigeonVar_list[2])
let identityToken: String? = nilOrValue(pigeonVar_list[3])
return AppleSignInModel(
userId: userId,
email: email,
nickname: nickname,
identityToken: identityToken
)
}
func toList() -> [Any?] {
return [
userId,
email,
nickname,
identityToken,
]
}
static func == (lhs: AppleSignInModel, rhs: AppleSignInModel) -> Bool {
return deepEqualsPlatformApi(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashPlatformApi(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct GoogleSignInModel: Hashable {
var email: String? = nil
var clientID: String? = nil
var idToken: String
var nickname: String? = nil
var avatarUrl: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> GoogleSignInModel? {
let email: String? = nilOrValue(pigeonVar_list[0])
let clientID: String? = nilOrValue(pigeonVar_list[1])
let idToken = pigeonVar_list[2] as! String
let nickname: String? = nilOrValue(pigeonVar_list[3])
let avatarUrl: String? = nilOrValue(pigeonVar_list[4])
return GoogleSignInModel(
email: email,
clientID: clientID,
idToken: idToken,
nickname: nickname,
avatarUrl: avatarUrl
)
}
func toList() -> [Any?] {
return [
email,
clientID,
idToken,
nickname,
avatarUrl,
]
}
static func == (lhs: GoogleSignInModel, rhs: GoogleSignInModel) -> Bool {
return deepEqualsPlatformApi(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashPlatformApi(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct WatchAppOtherInfo: Hashable {
var userId: Int64? = nil
var nickname: String? = nil
var markName: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> WatchAppOtherInfo? {
let userId: Int64? = nilOrValue(pigeonVar_list[0])
let nickname: String? = nilOrValue(pigeonVar_list[1])
let markName: String? = nilOrValue(pigeonVar_list[2])
return WatchAppOtherInfo(
userId: userId,
nickname: nickname,
markName: markName
)
}
func toList() -> [Any?] {
return [
userId,
nickname,
markName,
]
}
static func == (lhs: WatchAppOtherInfo, rhs: WatchAppOtherInfo) -> Bool {
return deepEqualsPlatformApi(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashPlatformApi(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct AppleProductInfo: Hashable {
/// 苹果商品id
var productId: String
/// 苹果商品名称
var productName: String
/// 原价描述
var originPriceDescription: String
/// 真实价格描述
var priceDescription: String
/// 原价格
var originPrice: Double
/// 真实价格, = 0 代表试用商品
var price: Double
/// price/unit = 单位价格
var unitPrice: String
/// 当前货币符号
var currencyCode: String
/// 当前用户是否可以试用
var isTrialPeriod: Bool
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> AppleProductInfo? {
let productId = pigeonVar_list[0] as! String
let productName = pigeonVar_list[1] as! String
let originPriceDescription = pigeonVar_list[2] as! String
let priceDescription = pigeonVar_list[3] as! String
let originPrice = pigeonVar_list[4] as! Double
let price = pigeonVar_list[5] as! Double
let unitPrice = pigeonVar_list[6] as! String
let currencyCode = pigeonVar_list[7] as! String
let isTrialPeriod = pigeonVar_list[8] as! Bool
return AppleProductInfo(
productId: productId,
productName: productName,
originPriceDescription: originPriceDescription,
priceDescription: priceDescription,
originPrice: originPrice,
price: price,
unitPrice: unitPrice,
currencyCode: currencyCode,
isTrialPeriod: isTrialPeriod
)
}
func toList() -> [Any?] {
return [
productId,
productName,
originPriceDescription,
priceDescription,
originPrice,
price,
unitPrice,
currencyCode,
isTrialPeriod,
]
}
static func == (lhs: AppleProductInfo, rhs: AppleProductInfo) -> Bool {
return deepEqualsPlatformApi(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashPlatformApi(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct AppleProductPaymentResult: Hashable {
var productId: String
var appAccountToken: String? = nil
var originalTransactionId: String? = nil
var transactionId: String? = nil
/// success 为空时是支付pending状态,不需要处理
/// 只有 true/false时才是支付结果出来的时候
var success: Bool? = nil
/// 错误描述, success = false时取用:
/// 优先取 errorCode: -1: UUID格式错误, -2: productID查询商品失败,-3:用户取消支付, -4:支付校验失败,-5:未知错误(Apple未知错误)
/// errorCode 为空时,取用 errorMessage
var errorMessage: String? = nil
var errorCode: Int64? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> AppleProductPaymentResult? {
let productId = pigeonVar_list[0] as! String
let appAccountToken: String? = nilOrValue(pigeonVar_list[1])
let originalTransactionId: String? = nilOrValue(pigeonVar_list[2])
let transactionId: String? = nilOrValue(pigeonVar_list[3])
let success: Bool? = nilOrValue(pigeonVar_list[4])
let errorMessage: String? = nilOrValue(pigeonVar_list[5])
let errorCode: Int64? = nilOrValue(pigeonVar_list[6])
return AppleProductPaymentResult(
productId: productId,
appAccountToken: appAccountToken,
originalTransactionId: originalTransactionId,
transactionId: transactionId,
success: success,
errorMessage: errorMessage,
errorCode: errorCode
)
}
func toList() -> [Any?] {
return [
productId,
appAccountToken,
originalTransactionId,
transactionId,
success,
errorMessage,
errorCode,
]
}
static func == (lhs: AppleProductPaymentResult, rhs: AppleProductPaymentResult) -> Bool {
return deepEqualsPlatformApi(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashPlatformApi(value: toList(), hasher: &hasher)
}
}
private class PlatformApiPigeonCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 129:
let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?)
if let enumResultAsInt = enumResultAsInt {
return HResourceType(rawValue: enumResultAsInt)
}
return nil
case 130:
return AppleSignInModel.fromList(self.readValue() as! [Any?])
case 131:
return GoogleSignInModel.fromList(self.readValue() as! [Any?])
case 132:
return WatchAppOtherInfo.fromList(self.readValue() as! [Any?])
case 133:
return AppleProductInfo.fromList(self.readValue() as! [Any?])
case 134:
return AppleProductPaymentResult.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
}
}
private class PlatformApiPigeonCodecWriter: FlutterStandardWriter {
override func writeValue(_ value: Any) {
if let value = value as? HResourceType {
super.writeByte(129)
super.writeValue(value.rawValue)
} else if let value = value as? AppleSignInModel {
super.writeByte(130)
super.writeValue(value.toList())
} else if let value = value as? GoogleSignInModel {
super.writeByte(131)
super.writeValue(value.toList())
} else if let value = value as? WatchAppOtherInfo {
super.writeByte(132)
super.writeValue(value.toList())
} else if let value = value as? AppleProductInfo {
super.writeByte(133)
super.writeValue(value.toList())
} else if let value = value as? AppleProductPaymentResult {
super.writeByte(134)
super.writeValue(value.toList())
} else {
super.writeValue(value)
}
}
}
private class PlatformApiPigeonCodecReaderWriter: FlutterStandardReaderWriter {
override func reader(with data: Data) -> FlutterStandardReader {
return PlatformApiPigeonCodecReader(data: data)
}
override func writer(with data: NSMutableData) -> FlutterStandardWriter {
return PlatformApiPigeonCodecWriter(data: data)
}
}
class PlatformApiPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
static let shared = PlatformApiPigeonCodec(readerWriter: PlatformApiPigeonCodecReaderWriter())
}
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol PlatformHostApi {
/// 返回完整的 User-Agent 字符串,由 native 侧组装:
/// `{systemWebViewUA} {appName}/{versionCode}({versionName})({manufacturer}##{brand}##{model}; {OS}{osVersion}; {height}x{width})(huawei)`
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)
/// 是否是测试环境
func isDebugEnvoriment() throws -> Bool
func shareText(text: String, completion: @escaping (Result<Bool, Error>) -> Void)
func shareFileData(databytes: FlutterStandardTypedData, completion: @escaping (Result<Bool, Error>) -> Void)
/// 更新用户信息, 有登录态后调用
/// jsonString: UserPreferences的序列化string
/// baseUrl: 请求地址, https://api.doublefeel.cn
func updateLoginInfo(jsonString: String, baseUrl: String) throws
/// 退出登录
func logout() throws
/// 刷新会员信息
func refreshVip() throws
/// 刷新watch app 和 表盘的所有数据:
/// 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
func refreshWatchAppAndWidgets() throws
/// 请求评分弹窗
func requestAppReview(completion: @escaping (Result<Bool, Error>) -> Void)
/// 跳app应用设置:通知、定位等权限
func jumpAppSetting() throws -> Bool
/// 原生处理跳转url
func nativeHandleUrl(urlString: String) throws -> Bool
/// 从原生拿需要处理的url, 主要场景是点击通知跳转
func requestUnhandedUrl() throws -> String?
/// 请求苹果登录
func requestAppleSignIn(completion: @escaping (Result<AppleSignInModel?, Error>) -> Void)
/// google登录
func requestGoogleSignIn(completion: @escaping (Result<GoogleSignInModel?, Error>) -> Void)
/// 发送邮件
func sendEmail(mailTo: String, title: String, content: String, completion: @escaping (Result<Bool, Error>) -> Void)
/// 查询指定id的苹果商品
/// productId: 苹果商品id
/// baseUnit: 除数基础单位(多少个天、周、月) ->
func requestAppleProductInfo(productId: String, baseUnit: Int64, completion: @escaping (Result<AppleProductInfo?, Error>) -> Void)
/// 从服务器下单后请求苹果支付
func performApplePayment(productId: String, uuid: String, completion: @escaping (Result<AppleProductPaymentResult?, Error>) -> Void)
/// 恢复购买
func performRestore(completion: @escaping (Result<Bool, Error>) -> Void)
/// 上传文件到云端
/// 注意catch flutter error
func uploadFile(filePath: String, resourceType: HResourceType, completion: @escaping (Result<String?, Error>) -> Void)
/// 原生切图片,
/// imageUrl: 图片本地地址
/// maxKB: 压缩大小
/// width.height 切图后输出的大小
func performCropImage(imageUrl: String, maxKB: Int64?, width: Int64?, height: Int64?, completion: @escaping (Result<String?, Error>) -> Void)
/// 发起本地推送
/// dataType: 0: hr ,1: hrv , 2: sleep
/// dateTime: 数据对应的时间戳
func sendLocalNotification(dataType: Int64, dateTime: Int64, title: String, content: String, link: String, completion: @escaping (Result<Bool, Error>) -> Void)
}
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class PlatformHostApiSetup {
static var codec: FlutterStandardMessageCodec { PlatformApiPigeonCodec.shared }
/// Sets up an instance of `PlatformHostApi` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: PlatformHostApi?, messageChannelSuffix: String = "") {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
/// 返回完整的 User-Agent 字符串,由 native 侧组装:
/// `{systemWebViewUA} {appName}/{versionCode}({versionName})({manufacturer}##{brand}##{model}; {OS}{osVersion}; {height}x{width})(huawei)`
let getFullUserAgentChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.getFullUserAgent\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
getFullUserAgentChannel.setMessageHandler { _, reply in
do {
let result = try api.getFullUserAgent()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
getFullUserAgentChannel.setMessageHandler(nil)
}
/// 是否是中国大陆地区
let isChinaRegionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.isChinaRegion\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
isChinaRegionChannel.setMessageHandler { _, reply in
api.isChinaRegion { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} 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 {
requestNotificationAuthChannel.setMessageHandler { _, reply in
api.requestNotificationAuth { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
requestNotificationAuthChannel.setMessageHandler(nil)
}
/// 是否是测试环境
let isDebugEnvorimentChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.isDebugEnvoriment\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
isDebugEnvorimentChannel.setMessageHandler { _, reply in
do {
let result = try api.isDebugEnvoriment()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
isDebugEnvorimentChannel.setMessageHandler(nil)
}
let shareTextChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.shareText\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
shareTextChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let textArg = args[0] as! String
api.shareText(text: textArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
shareTextChannel.setMessageHandler(nil)
}
let shareFileDataChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.shareFileData\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
shareFileDataChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let databytesArg = args[0] as! FlutterStandardTypedData
api.shareFileData(databytes: databytesArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
shareFileDataChannel.setMessageHandler(nil)
}
/// 更新用户信息, 有登录态后调用
/// jsonString: UserPreferences的序列化string
/// baseUrl: 请求地址, https://api.doublefeel.cn
let updateLoginInfoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.updateLoginInfo\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
updateLoginInfoChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let jsonStringArg = args[0] as! String
let baseUrlArg = args[1] as! String
do {
try api.updateLoginInfo(jsonString: jsonStringArg, baseUrl: baseUrlArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
updateLoginInfoChannel.setMessageHandler(nil)
}
/// 退出登录
let logoutChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.logout\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
logoutChannel.setMessageHandler { _, reply in
do {
try api.logout()
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
logoutChannel.setMessageHandler(nil)
}
/// 刷新会员信息
let refreshVipChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshVip\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
refreshVipChannel.setMessageHandler { _, reply in
do {
try api.refreshVip()
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
refreshVipChannel.setMessageHandler(nil)
}
/// 刷新watch app 和 表盘的所有数据:
/// 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
let refreshWatchAppAndWidgetsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshWatchAppAndWidgets\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
refreshWatchAppAndWidgetsChannel.setMessageHandler { _, reply in
do {
try api.refreshWatchAppAndWidgets()
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
refreshWatchAppAndWidgetsChannel.setMessageHandler(nil)
}
/// 请求评分弹窗
let requestAppReviewChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestAppReview\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
requestAppReviewChannel.setMessageHandler { _, reply in
api.requestAppReview { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
requestAppReviewChannel.setMessageHandler(nil)
}
/// 跳app应用设置:通知、定位等权限
let jumpAppSettingChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.jumpAppSetting\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
jumpAppSettingChannel.setMessageHandler { _, reply in
do {
let result = try api.jumpAppSetting()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
jumpAppSettingChannel.setMessageHandler(nil)
}
/// 原生处理跳转url
let nativeHandleUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.nativeHandleUrl\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
nativeHandleUrlChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let urlStringArg = args[0] as! String
do {
let result = try api.nativeHandleUrl(urlString: urlStringArg)
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
nativeHandleUrlChannel.setMessageHandler(nil)
}
/// 从原生拿需要处理的url, 主要场景是点击通知跳转
let requestUnhandedUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestUnhandedUrl\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
requestUnhandedUrlChannel.setMessageHandler { _, reply in
do {
let result = try api.requestUnhandedUrl()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
requestUnhandedUrlChannel.setMessageHandler(nil)
}
/// 请求苹果登录
let requestAppleSignInChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestAppleSignIn\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
requestAppleSignInChannel.setMessageHandler { _, reply in
api.requestAppleSignIn { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
requestAppleSignInChannel.setMessageHandler(nil)
}
/// google登录
let requestGoogleSignInChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestGoogleSignIn\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
requestGoogleSignInChannel.setMessageHandler { _, reply in
api.requestGoogleSignIn { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
requestGoogleSignInChannel.setMessageHandler(nil)
}
/// 发送邮件
let sendEmailChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.sendEmail\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
sendEmailChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let mailToArg = args[0] as! String
let titleArg = args[1] as! String
let contentArg = args[2] as! String
api.sendEmail(mailTo: mailToArg, title: titleArg, content: contentArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
sendEmailChannel.setMessageHandler(nil)
}
/// 查询指定id的苹果商品
/// productId: 苹果商品id
/// baseUnit: 除数基础单位(多少个天、周、月) ->
let requestAppleProductInfoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestAppleProductInfo\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
requestAppleProductInfoChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let productIdArg = args[0] as! String
let baseUnitArg = args[1] as! Int64
api.requestAppleProductInfo(productId: productIdArg, baseUnit: baseUnitArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
requestAppleProductInfoChannel.setMessageHandler(nil)
}
/// 从服务器下单后请求苹果支付
let performApplePaymentChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.performApplePayment\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
performApplePaymentChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let productIdArg = args[0] as! String
let uuidArg = args[1] as! String
api.performApplePayment(productId: productIdArg, uuid: uuidArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
performApplePaymentChannel.setMessageHandler(nil)
}
/// 恢复购买
let performRestoreChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.performRestore\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
performRestoreChannel.setMessageHandler { _, reply in
api.performRestore { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
performRestoreChannel.setMessageHandler(nil)
}
/// 上传文件到云端
/// 注意catch flutter error
let uploadFileChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.uploadFile\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
uploadFileChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let filePathArg = args[0] as! String
let resourceTypeArg = args[1] as! HResourceType
api.uploadFile(filePath: filePathArg, resourceType: resourceTypeArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
uploadFileChannel.setMessageHandler(nil)
}
/// 原生切图片,
/// imageUrl: 图片本地地址
/// maxKB: 压缩大小
/// width.height 切图后输出的大小
let performCropImageChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.performCropImage\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
performCropImageChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let imageUrlArg = args[0] as! String
let maxKBArg: Int64? = nilOrValue(args[1])
let widthArg: Int64? = nilOrValue(args[2])
let heightArg: Int64? = nilOrValue(args[3])
api.performCropImage(imageUrl: imageUrlArg, maxKB: maxKBArg, width: widthArg, height: heightArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
performCropImageChannel.setMessageHandler(nil)
}
/// 发起本地推送
/// dataType: 0: hr ,1: hrv , 2: sleep
/// dateTime: 数据对应的时间戳
let sendLocalNotificationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.sendLocalNotification\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
sendLocalNotificationChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let dataTypeArg = args[0] as! Int64
let dateTimeArg = args[1] as! Int64
let titleArg = args[2] as! String
let contentArg = args[3] as! String
let linkArg = args[4] as! String
api.sendLocalNotification(dataType: dataTypeArg, dateTime: dateTimeArg, title: titleArg, content: contentArg, link: linkArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
sendLocalNotificationChannel.setMessageHandler(nil)
}
}
}