Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/*
2
 * Copyright 2017 Google
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
#import <Foundation/Foundation.h>
18
 
19
NS_ASSUME_NONNULL_BEGIN
20
 
21
/**
22
 *  @related FIRMessaging
23
 *
24
 *  The completion handler invoked when the registration token returns.
25
 *  If the call fails we return the appropriate `error code`, described by
26
 *  `FIRMessagingError`.
27
 *
28
 *  @param FCMToken  The valid registration token returned by FCM.
29
 *  @param error     The error describing why a token request failed. The error code
30
 *                   will match a value from the FIRMessagingError enumeration.
31
 */
32
typedef void (^FIRMessagingFCMTokenFetchCompletion)(NSString *_Nullable FCMToken,
33
                                                    NSError *_Nullable error)
34
    NS_SWIFT_NAME(MessagingFCMTokenFetchCompletion);
35
 
36
/**
37
 *  @related FIRMessaging
38
 *
39
 *  The completion handler invoked when the registration token deletion request is
40
 *  completed. If the call fails we return the appropriate `error code`, described
41
 *  by `FIRMessagingError`.
42
 *
43
 *  @param error The error describing why a token deletion failed. The error code
44
 *               will match a value from the FIRMessagingError enumeration.
45
 */
46
typedef void (^FIRMessagingDeleteFCMTokenCompletion)(NSError *_Nullable error)
47
    NS_SWIFT_NAME(MessagingDeleteFCMTokenCompletion);
48
 
49
/**
50
 *  Callback to invoke once the HTTP call to FIRMessaging backend for updating
51
 *  subscription finishes.
52
 *
53
 *  @param error  The error which occurred while updating the subscription topic
54
 *                on the FIRMessaging server. This will be nil in case the operation
55
 *                was successful, or if the operation was cancelled.
56
 */
57
typedef void (^FIRMessagingTopicOperationCompletion)(NSError *_Nullable error);
58
 
59
/**
60
 *  Notification sent when the FCM registration token has been refreshed. Please use the
61
 *  FIRMessaging delegate method `messaging:didReceiveRegistrationToken:` to receive current and
62
 *  updated tokens.
63
 */
64
// clang-format off
65
// clang-format12 merges the next two lines.
66
FOUNDATION_EXPORT const NSNotificationName FIRMessagingRegistrationTokenRefreshedNotification
67
    NS_SWIFT_NAME(MessagingRegistrationTokenRefreshed);
68
// clang-format on
69
 
70
/**
71
 *  @enum FIRMessagingError
72
 */
73
typedef NS_ENUM(NSUInteger, FIRMessagingError) {
74
  /// Unknown error.
75
  FIRMessagingErrorUnknown = 0,
76
 
77
  /// FIRMessaging couldn't validate request from this client.
78
  FIRMessagingErrorAuthentication = 1,
79
 
80
  /// InstanceID service cannot be accessed.
81
  FIRMessagingErrorNoAccess = 2,
82
 
83
  /// Request to InstanceID backend timed out.
84
  FIRMessagingErrorTimeout = 3,
85
 
86
  /// No network available to reach the servers.
87
  FIRMessagingErrorNetwork = 4,
88
 
89
  /// Another similar operation in progress, bailing this one.
90
  FIRMessagingErrorOperationInProgress = 5,
91
 
92
  /// Some parameters of the request were invalid.
93
  FIRMessagingErrorInvalidRequest = 7,
94
 
95
  /// Topic name is invalid for subscription/unsubscription.
96
  FIRMessagingErrorInvalidTopicName = 8,
97
 
98
} NS_SWIFT_NAME(MessagingError);
99
 
100
/// Status for the downstream message received by the app.
101
typedef NS_ENUM(NSInteger, FIRMessagingMessageStatus) {
102
  /// Unknown status.
103
  FIRMessagingMessageStatusUnknown,
104
  /// New downstream message received by the app.
105
  FIRMessagingMessageStatusNew,
106
} NS_SWIFT_NAME(MessagingMessageStatus);
107
 
108
/**
109
 *  The APNs token type for the app. If the token type is set to `UNKNOWN`
110
 *  Firebase Messaging will implicitly try to figure out what the actual token type
111
 *  is from the provisioning profile.
112
 *  Unless you really need to specify the type, you should use the `APNSToken`
113
 *  property instead.
114
 */
115
typedef NS_ENUM(NSInteger, FIRMessagingAPNSTokenType) {
116
  /// Unknown token type.
117
  FIRMessagingAPNSTokenTypeUnknown,
118
  /// Sandbox token type.
119
  FIRMessagingAPNSTokenTypeSandbox,
120
  /// Production token type.
121
  FIRMessagingAPNSTokenTypeProd,
122
} NS_SWIFT_NAME(MessagingAPNSTokenType);
123
 
124
/// Information about a downstream message received by the app.
125
NS_SWIFT_NAME(MessagingMessageInfo)
126
@interface FIRMessagingMessageInfo : NSObject
127
 
128
/// The status of the downstream message
129
@property(nonatomic, readonly, assign) FIRMessagingMessageStatus status;
130
 
131
@end
132
 
133
@class FIRMessaging;
134
@class FIRMessagingExtensionHelper;
135
 
136
/**
137
 * A protocol to handle token update or data message delivery from FCM.
138
 *
139
 */
140
NS_SWIFT_NAME(MessagingDelegate)
141
@protocol FIRMessagingDelegate <NSObject>
142
 
143
@optional
144
/// This method will be called once a token is available, or has been refreshed. Typically it
145
/// will be called once per app start, but may be called more often, if token is invalidated or
146
/// updated. In this method, you should perform operations such as:
147
///
148
/// * Uploading the FCM token to your application server, so targeted notifications can be sent.
149
///
150
/// * Subscribing to any topics.
151
- (void)messaging:(FIRMessaging *)messaging
152
    didReceiveRegistrationToken:(nullable NSString *)fcmToken
153
    NS_SWIFT_NAME(messaging(_:didReceiveRegistrationToken:));
154
@end
155
 
156
/**
157
 *  Firebase Messaging lets you reliably deliver messages at no cost.
158
 *
159
 *  To send or receive messages, the app must get a
160
 *  registration token. This token authorizes an
161
 *  app server to send messages to an app instance.
162
 *
163
 *  In order to receive FIRMessaging messages, declare
164
 *  `application:didReceiveRemoteNotification::fetchCompletionHandler:`.
165
 */
166
NS_SWIFT_NAME(Messaging)
167
@interface FIRMessaging : NSObject
168
 
169
/**
170
 * Delegate to handle FCM token refreshes, and remote data messages received via FCM direct channel.
171
 */
172
@property(nonatomic, weak, nullable) id<FIRMessagingDelegate> delegate;
173
 
174
/**
175
 *  FIRMessaging
176
 *
177
 *  @return An instance of FIRMessaging.
178
 */
179
+ (instancetype)messaging NS_SWIFT_NAME(messaging());
180
 
181
/**
182
 * FIRMessagingExtensionHelper
183
 *
184
 * Use FIRMessagingExtensionHelper to populate rich UI contents for your notifications.
185
 * e.g. If an image URL is set in your notification payload or on the console, call
186
 * FIRMessagingExtensionHelper API to render it on your notification.
187
 *
188
 * @return An instance of FIRMessagingExtensionHelper that handles the extensions API.
189
 */
190
+ (FIRMessagingExtensionHelper *)extensionHelper NS_SWIFT_NAME(serviceExtension())
191
    NS_AVAILABLE(10.14, 10.0);
192
 
193
/**
194
 *  Unavailable. Use +messaging instead.
195
 */
196
- (instancetype)init __attribute__((unavailable("Use +messaging instead.")));
197
 
198
#pragma mark - APNs
199
 
200
/**
201
 *  This property is used to set the APNs Token received by the application delegate.
202
 *
203
 *  FIRMessaging uses method swizzling to ensure that the APNs token is set
204
 *  automatically. However, if you have disabled swizzling by setting
205
 *  `FirebaseAppDelegateProxyEnabled` to `NO` in your app's
206
 *  Info.plist, you should manually set the APNs token in your application
207
 *  delegate's `-application:didRegisterForRemoteNotificationsWithDeviceToken:`
208
 *  method.
209
 *
210
 *  If you would like to set the type of the APNs token, rather than relying on
211
 *  automatic detection, see: `-setAPNSToken:type:`.
212
 */
213
@property(nonatomic, copy, nullable) NSData *APNSToken NS_SWIFT_NAME(apnsToken);
214
 
215
/**
216
 *  Set APNs token for the application. This APNs token will be used to register
217
 *  with Firebase Messaging using `FCMToken` or
218
 *  `tokenWithAuthorizedEntity:scope:options:handler`.
219
 *
220
 *  @param apnsToken The APNs token for the application.
221
 *  @param type  The type of APNs token. Debug builds should use
222
 *  FIRMessagingAPNSTokenTypeSandbox. Alternatively, you can supply
223
 *  FIRMessagingAPNSTokenTypeUnknown to have the type automatically
224
 *  detected based on your provisioning profile.
225
 */
226
- (void)setAPNSToken:(NSData *)apnsToken type:(FIRMessagingAPNSTokenType)type;
227
 
228
#pragma mark - FCM Tokens
229
 
230
/**
231
 * Is Firebase Messaging token auto generation enabled?  If this flag is disabled, Firebase
232
 * Messaging will not generate token automatically for message delivery.
233
 *
234
 * If this flag is disabled, Firebase Messaging does not generate new tokens automatically for
235
 * message delivery. If this flag is enabled, FCM generates a registration token on application
236
 * start when there is no existing valid token and periodically refreshes the token and sends
237
 * data to Firebase backend.
238
 *
239
 * This setting is persisted, and is applied on future invocations of your application.  Once
240
 * explicitly set, it overrides any settings in your Info.plist.
241
 *
242
 * By default, FCM automatic initialization is enabled.  If you need to change the
243
 * default (for example, because you want to prompt the user before getting token)
244
 * set FirebaseMessagingAutoInitEnabled to false in your application's Info.plist.
245
 */
246
@property(nonatomic, assign, getter=isAutoInitEnabled) BOOL autoInitEnabled;
247
 
248
/**
249
 * The FCM registration token is used to identify this device so that FCM can send notifications to
250
 * it. It is associated with your APNs token when the APNs token is supplied, so messages sent to
251
 * the FCM token will be delivered over APNs.
252
 *
253
 * The FCM registration token is sometimes refreshed automatically. In your FIRMessaging delegate,
254
 * the delegate method `messaging:didReceiveRegistrationToken:` will be called once a token is
255
 * available, or has been refreshed. Typically it should be called once per app start, but
256
 * may be called more often if the token is invalidated or updated.
257
 *
258
 * Once you have an FCM registration token, you should send it to your application server, so it can
259
 * use the FCM token to send notifications to your device.
260
 */
261
@property(nonatomic, readonly, nullable) NSString *FCMToken NS_SWIFT_NAME(fcmToken);
262
 
263
/**
264
 * Asynchronously gets the default FCM registration token.
265
 *
266
 * This creates a Firebase Installations ID, if one does not exist, and sends information about the
267
 * application and the device to the Firebase backend. A network connection is required for the
268
 * method to succeed. To stop this, see `Messaging.isAutoInitEnabled`,
269
 * `Messaging.delete(completion:)` and `Installations.delete(completion:)`.
270
 *
271
 * @param completion The completion handler to handle the token request.
272
 */
273
 
274
- (void)tokenWithCompletion:(void (^)(NSString *__nullable token,
275
                                      NSError *__nullable error))completion;
276
 
277
/**
278
 * Asynchronously deletes the default FCM registration token.
279
 *
280
 * This does not delete all tokens for non-default sender IDs, See `Messaging.delete(completion:)`
281
 * for deleting all of them. To prevent token auto generation, see `Messaging.isAutoInitEnabled`.
282
 *
283
 * @param completion The completion handler to handle the token deletion.
284
 */
285
 
286
- (void)deleteTokenWithCompletion:(void (^)(NSError *__nullable error))completion;
287
 
288
/**
289
 *  Retrieves an FCM registration token for a particular Sender ID. This can be used to allow
290
 *  multiple senders to send notifications to the same device. By providing a different Sender
291
 *  ID than your default when fetching a token, you can create a new FCM token which you can
292
 *  give to a different sender. Both tokens will deliver notifications to your device, and you
293
 *  can revoke a token when you need to.
294
 *
295
 *  This registration token is not cached by FIRMessaging. FIRMessaging should have an APNs
296
 *  token set before calling this to ensure that notifications can be delivered via APNs using
297
 *  this FCM token. You may re-retrieve the FCM token once you have the APNs token set, to
298
 *  associate it with the FCM token. The default FCM token is automatically associated with
299
 *  the APNs token, if the APNs token data is available.
300
 *
301
 *  This creates a Firebase Installations ID, if one does not exist, and sends information
302
 *  about the application and the device to the Firebase backend.
303
 *
304
 *  @param senderID The Sender ID for a particular Firebase project.
305
 *  @param completion The completion handler to handle the token request.
306
 */
307
- (void)retrieveFCMTokenForSenderID:(NSString *)senderID
308
                         completion:(void (^)(NSString *_Nullable FCMToken,
309
                                              NSError *_Nullable error))completion
310
    NS_SWIFT_NAME(retrieveFCMToken(forSenderID:completion:));
311
 
312
/**
313
 * Invalidates an FCM token for a particular Sender ID. That Sender ID cannot no longer send
314
 * notifications to that FCM token. This does not delete the Firebase Installations ID that may have
315
 * been created when generating the token. See `Installations.delete(completion:)`.
316
 *
317
 * @param senderID The senderID for a particular Firebase project.
318
 * @param completion The completion handler to handle the token deletion.
319
 */
320
- (void)deleteFCMTokenForSenderID:(NSString *)senderID
321
                       completion:(void (^)(NSError *_Nullable error))completion
322
    NS_SWIFT_NAME(deleteFCMToken(forSenderID:completion:));
323
 
324
#pragma mark - Topics
325
 
326
/**
327
 * Asynchronously subscribes to a topic. This uses the default FCM registration token to identify
328
 * the app instance and periodically sends data to the Firebase backend. To stop this, see
329
 * `Messaging.delete(completion:)` and `Installations.delete(completion:)`.
330
 *
331
 * @param topic The name of the topic, for example, @"sports".
332
 */
333
- (void)subscribeToTopic:(NSString *)topic NS_SWIFT_NAME(subscribe(toTopic:));
334
 
335
/**
336
 * Asynchronously subscribe to the provided topic, retrying on failure. This uses the default FCM
337
 * registration token to identify the app instance and periodically sends data to the Firebase
338
 * backend. To stop this, see `Messaging.delete(completion:)` and
339
 * `Installations.delete(completion:)`.
340
 *
341
 * @param topic       The topic name to subscribe to, for example, @"sports".
342
 * @param completion  The completion that is invoked once the subscribe call ends.
343
 *                     In case of success, nil error is returned. Otherwise, an
344
 *                     appropriate error object is returned.
345
 */
346
- (void)subscribeToTopic:(nonnull NSString *)topic
347
              completion:(void (^_Nullable)(NSError *_Nullable error))completion;
348
 
349
/**
350
 * Asynchronously unsubscribe from a topic.  This uses a FCM Token
351
 * to identify the app instance and periodically sends data to the Firebase backend. To stop this,
352
 * see `Messaging.delete(completion:)` and `Installations.delete(completion:)`.
353
 *
354
 * @param topic The name of the topic, for example @"sports".
355
 */
356
- (void)unsubscribeFromTopic:(NSString *)topic NS_SWIFT_NAME(unsubscribe(fromTopic:));
357
 
358
/**
359
 * Asynchronously unsubscribe from the provided topic, retrying on failure. This uses a FCM Token
360
 * to identify the app instance and periodically sends data to the Firebase backend. To stop this,
361
 * see `Messaging.delete(completion:)` and `Installations.delete(completion:)`.
362
 *
363
 *  @param topic       The topic name to unsubscribe from, for example @"sports".
364
 *  @param completion  The completion that is invoked once the unsubscribe call ends.
365
 *                     In case of success, nil error is returned. Otherwise, an
366
 *                     appropriate error object is returned.
367
 */
368
- (void)unsubscribeFromTopic:(nonnull NSString *)topic
369
                  completion:(void (^_Nullable)(NSError *_Nullable error))completion;
370
 
371
#pragma mark - Analytics
372
 
373
/**
374
 *  Use this to track message delivery and analytics for messages, typically
375
 *  when you receive a notification in `application:didReceiveRemoteNotification:`.
376
 *  However, you only need to call this if you set the `FirebaseAppDelegateProxyEnabled`
377
 *  flag to `NO` in your Info.plist. If `FirebaseAppDelegateProxyEnabled` is either missing
378
 *  or set to `YES` in your Info.plist, the library will call this automatically.
379
 *
380
 *  @param message The downstream message received by the application.
381
 *
382
 *  @return Information about the downstream message.
383
 */
384
- (FIRMessagingMessageInfo *)appDidReceiveMessage:(NSDictionary *)message;
385
 
386
#pragma mark - GDPR
387
/**
388
 * Deletes all the tokens and checkin data of the Firebase project and related data on the server
389
 * side. A network connection is required for the method to succeed.
390
 *
391
 * This does not delete the Firebase Installations ID. See `Installations.delete(completion:)`.
392
 * To prevent token auto generation, see `Messaging.isAutoInitEnabled`.
393
 *
394
 * @param completion A completion handler which is invoked when the operation completes. `error ==
395
 * nil` indicates success.
396
 */
397
- (void)deleteDataWithCompletion:(void (^)(NSError *__nullable error))completion;
398
 
399
@end
400
 
401
NS_ASSUME_NONNULL_END