@@ -22,15 +22,69 @@ import UserNotifications
22
22
// exercised in the integration tests.
23
23
func apis( ) {
24
24
let messaging = Messaging . messaging ( )
25
+ let delegate = CustomDelegate ( )
26
+ messaging. delegate = delegate
27
+ messaging. isAutoInitEnabled = false
28
+ messaging. token ( completion: { _, _ in
29
+ } )
30
+ messaging. deleteToken { _ in
31
+ }
32
+ messaging. retrieveFCMToken ( forSenderID: " fakeSenderID " ) { _, _ in
33
+ }
34
+ messaging. deleteData { _ in
35
+ }
36
+ messaging. deleteFCMToken ( forSenderID: " fakeSenderID " ) { _ in
37
+ }
25
38
26
39
if let _ = messaging. apnsToken { }
27
40
28
41
let apnsToken = Data ( )
29
42
messaging. setAPNSToken ( apnsToken, type: . prod)
30
43
44
+ // Use random to eliminate the warning that we're evaluating to a constant.
45
+ let type : MessagingAPNSTokenType = Bool . random ( ) ? . prod : . sandbox
46
+ switch type {
47
+ case . prod: ( )
48
+ case . sandbox: ( )
49
+ case . unknown: ( )
50
+ // Intentionally leave the warning for not handling unknown values as that's the only way this
51
+ // will fail to compile if we add a case.
52
+ }
53
+
54
+ // Use random to eliminate the warning that we're evaluating to a constant.
55
+ let messagingError : MessagingError = Bool . random ( ) ? . unknown : . authentication
56
+ switch messagingError {
57
+ case . unknown: ( )
58
+ case . authentication: ( )
59
+ case . noAccess: ( )
60
+ case . timeout: ( )
61
+ case . network: ( )
62
+ case . operationInProgress: ( )
63
+ case . invalidRequest: ( )
64
+ case . invalidTopicName: ( )
65
+ // Intentionally leave the warning for not handling unknown values as that's the only way this
66
+ // will fail to compile if we add a case.
67
+ }
68
+
69
+ // Use random to eliminate the warning that we're evaluating to a constant.
70
+ let status : MessagingMessageStatus = Bool . random ( ) ? . unknown : . new
71
+ switch status {
72
+ case . new: ( )
73
+ case . unknown: ( )
74
+ // Intentionally leave the warning for not handling unknown values as that's the only way this
75
+ // will fail to compile if we add a case.
76
+ }
77
+
78
+ // TODO: Mark the initializer as unavialable, as devs shouldn't be able to instantiate this.
79
+ _ = MessagingMessageInfo ( ) . status
80
+
81
+ NotificationCenter . default. post ( name: . MessagingRegistrationTokenRefreshed, object: nil )
82
+
31
83
let topic = " cat_video "
32
84
messaging. subscribe ( toTopic: topic)
33
85
messaging. unsubscribe ( fromTopic: topic)
86
+ messaging. unsubscribe ( fromTopic: topic) { _ in
87
+ }
34
88
35
89
messaging. appDidReceiveMessage ( [ : ] )
36
90
@@ -43,6 +97,10 @@ func apis() {
43
97
}
44
98
}
45
99
100
+ class CustomDelegate : NSObject , MessagingDelegate {
101
+ func messaging( _ messaging: Messaging , didReceiveRegistrationToken fcmToken: String ? ) { }
102
+ }
103
+
46
104
@available ( iOS 15 , tvOS 15 , macOS 12 , watchOS 8 , * )
47
105
func apiAsync( ) async throws {
48
106
let messaging = Messaging . messaging ( )
0 commit comments