Skip to content

Commit b2ef5d9

Browse files
committed
conform messaging to sendable, where appropriate
1 parent b01a8f2 commit b2ef5d9

File tree

6 files changed

+54
-48
lines changed

6 files changed

+54
-48
lines changed

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class HeartbeatStorage: Sendable, HeartbeatStorageProtocol {
5959
// `nonisolated(unsafe)` to disable concurrency-safety checks. The
6060
// property's access is protected by an external synchronization mechanism
6161
// (see `instancesLock` property).
62-
private nonisolated(unsafe) static var cachedInstances: AtomicBox<
62+
private nonisolated(unsafe) static var cachedInstances: FirebaseCoreInternal.AtomicBox<
6363
[String: WeakContainer<HeartbeatStorage>]
6464
> = AtomicBox([:])
6565
#else

FirebaseFunctions/Sources/Callable+Codable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public extension Callable where Request: Sendable, Response: Sendable {
282282
// `StreamResponseProtocol`, we know the `Response` generic argument
283283
// is `StreamResponse<_, _>`.
284284
let responseJSON = switch response {
285-
case .message(let json), .result(let json): json
285+
case let .message(json), let .result(json): json
286286
}
287287
let response = try decoder.decode(Response.self, from: responseJSON)
288288
if response is StreamResponseProtocol {

FirebaseMessaging/Sources/FIRMessagingExtensionHelper.m

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,39 +97,33 @@ - (NSData *)transportBytes {
9797

9898
@end
9999

100-
@interface FIRMessagingExtensionHelper ()
101-
@property(nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
102-
@property(nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
103-
104-
@end
105-
106100
@implementation FIRMessagingExtensionHelper
107101

108102
- (void)populateNotificationContent:(UNMutableNotificationContent *)content
109103
withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler {
110-
self.contentHandler = [contentHandler copy];
111-
self.bestAttemptContent = content;
104+
__block void (^handler)(UNNotificationContent *_Nonnull) = [contentHandler copy];
105+
__block UNMutableNotificationContent *bestAttemptContent = [content mutableCopy];
112106

113107
// The `userInfo` property isn't available on newer versions of tvOS.
114108
#if !TARGET_OS_TV
115109
NSObject *currentImageURL = content.userInfo[kPayloadOptionsName][kPayloadOptionsImageURLName];
116110
if (!currentImageURL || currentImageURL == [NSNull null]) {
117-
[self deliverNotification];
111+
[self deliverNotificationWithContent:bestAttemptContent handler:handler];
118112
return;
119113
}
120114
NSURL *attachmentURL = [NSURL URLWithString:(NSString *)currentImageURL];
121115
if (attachmentURL) {
122116
[self loadAttachmentForURL:attachmentURL
123117
completionHandler:^(UNNotificationAttachment *attachment) {
124118
if (attachment != nil) {
125-
self.bestAttemptContent.attachments = @[ attachment ];
119+
bestAttemptContent.attachments = @[ attachment ];
126120
}
127-
[self deliverNotification];
121+
[self deliverNotificationWithContent:bestAttemptContent handler:handler];
128122
}];
129123
} else {
130124
FIRMessagingLoggerError(kFIRMessagingServiceExtensionImageInvalidURL,
131125
@"The Image URL provided is invalid %@.", currentImageURL);
132-
[self deliverNotification];
126+
[self deliverNotificationWithContent:bestAttemptContent handler:handler];
133127
}
134128
#else // !TARGET_OS_TV
135129
[self deliverNotification];
@@ -150,14 +144,15 @@ - (NSString *)fileExtensionForResponse:(NSURLResponse *)response {
150144
}
151145

152146
- (void)loadAttachmentForURL:(NSURL *)attachmentURL
153-
completionHandler:(void (^)(UNNotificationAttachment *))completionHandler {
154-
__block UNNotificationAttachment *attachment = nil;
155-
147+
completionHandler:
148+
(void (^NS_SWIFT_SENDABLE)(UNNotificationAttachment *))completionHandler
149+
NS_SWIFT_SENDABLE {
156150
NSURLSession *session = [NSURLSession
157151
sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
158152
[[session
159153
downloadTaskWithURL:attachmentURL
160154
completionHandler:^(NSURL *temporaryFileLocation, NSURLResponse *response, NSError *error) {
155+
UNNotificationAttachment *attachment = nil;
161156
if (error != nil) {
162157
FIRMessagingLoggerError(kFIRMessagingServiceExtensionImageNotDownloaded,
163158
@"Failed to download image given URL %@, error: %@\n",
@@ -196,9 +191,10 @@ - (void)loadAttachmentForURL:(NSURL *)attachmentURL
196191
}
197192
#endif // !TARGET_OS_TV
198193

199-
- (void)deliverNotification {
200-
if (self.contentHandler) {
201-
self.contentHandler(self.bestAttemptContent);
194+
- (void)deliverNotificationWithContent:(UNNotificationContent *)content
195+
handler:(void (^_Nullable)(UNNotificationContent *_Nonnull))handler {
196+
if (handler) {
197+
handler(content);
202198
}
203199
}
204200

FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessaging+ExtensionHelper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ NS_ASSUME_NONNULL_BEGIN
3232
*
3333
* @return An instance of MessagingExtensionHelper that handles the extensions API.
3434
*/
35-
+ (FIRMessagingExtensionHelper *)extensionHelper NS_SWIFT_NAME(serviceExtension());
35+
+ (FIRMessagingExtensionHelper *)extensionHelper NS_SWIFT_NAME(serviceExtension())
36+
NS_SWIFT_SENDABLE;
3637

3738
@end
3839

FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessaging.h

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ NS_SWIFT_NAME(MessagingDelegate)
154154
/// * Subscribing to any topics.
155155
- (void)messaging:(FIRMessaging *)messaging
156156
didReceiveRegistrationToken:(nullable NSString *)fcmToken
157-
NS_SWIFT_NAME(messaging(_:didReceiveRegistrationToken:));
157+
NS_SWIFT_NAME(messaging(_:didReceiveRegistrationToken:)) NS_SWIFT_UI_ACTOR;
158158
@end
159159

160160
/**
@@ -174,7 +174,7 @@ NS_SWIFT_NAME(Messaging)
174174
/**
175175
* Delegate to handle FCM token refreshes, and remote data messages received via FCM direct channel.
176176
*/
177-
@property(nonatomic, weak, nullable) id<FIRMessagingDelegate> delegate;
177+
@property(nonatomic, weak, nullable) id<FIRMessagingDelegate> delegate NS_SWIFT_UI_ACTOR;
178178

179179
/**
180180
* FIRMessaging
@@ -203,7 +203,7 @@ NS_SWIFT_NAME(Messaging)
203203
* If you would like to set the type of the APNs token, rather than relying on
204204
* automatic detection, see `setAPNSToken(_:type:)`.
205205
*/
206-
@property(nonatomic, copy, nullable) NSData *APNSToken NS_SWIFT_NAME(apnsToken);
206+
@property(nonatomic, copy, nullable) NSData *APNSToken NS_SWIFT_NAME(apnsToken) NS_SWIFT_UI_ACTOR;
207207

208208
/**
209209
* Set the APNs token for the application. This token will be used to register
@@ -216,7 +216,7 @@ NS_SWIFT_NAME(Messaging)
216216
* `MessagingAPNSTokenTypeUnknown` to have the type automatically
217217
* detected based on your provisioning profile.
218218
*/
219-
- (void)setAPNSToken:(NSData *)apnsToken type:(FIRMessagingAPNSTokenType)type;
219+
- (void)setAPNSToken:(NSData *)apnsToken type:(FIRMessagingAPNSTokenType)type NS_SWIFT_UI_ACTOR;
220220

221221
#pragma mark - FCM Tokens
222222

@@ -236,7 +236,7 @@ NS_SWIFT_NAME(Messaging)
236236
* default (for example, because you want to prompt the user before getting a token),
237237
* set `FirebaseMessagingAutoInitEnabled` to NO in your application's Info.plist.
238238
*/
239-
@property(nonatomic, assign, getter=isAutoInitEnabled) BOOL autoInitEnabled;
239+
@property(nonatomic, assign, getter=isAutoInitEnabled) BOOL autoInitEnabled NS_SWIFT_UI_ACTOR;
240240

241241
/**
242242
* The FCM registration token is used to identify this device so that FCM can send notifications to
@@ -251,7 +251,8 @@ NS_SWIFT_NAME(Messaging)
251251
* Once you have an FCM registration token, you should send it to your application server, where
252252
* it can be used to send notifications to your device.
253253
*/
254-
@property(nonatomic, readonly, nullable) NSString *FCMToken NS_SWIFT_NAME(fcmToken);
254+
@property(nonatomic, readonly, nullable) NSString *FCMToken NS_SWIFT_NAME(fcmToken)
255+
NS_SWIFT_UI_ACTOR;
255256

256257
/**
257258
* Asynchronously gets the default FCM registration token.
@@ -263,9 +264,9 @@ NS_SWIFT_NAME(Messaging)
263264
*
264265
* @param completion The completion handler to handle the token request.
265266
*/
266-
267-
- (void)tokenWithCompletion:(void (^)(NSString *_Nullable token,
268-
NSError *_Nullable error))completion;
267+
- (void)tokenWithCompletion:
268+
(void (^NS_SWIFT_UI_ACTOR)(NSString *_Nullable token, NSError *_Nullable error))completion
269+
NS_SWIFT_UI_ACTOR;
269270

270271
/**
271272
* Asynchronously deletes the default FCM registration token.
@@ -275,8 +276,8 @@ NS_SWIFT_NAME(Messaging)
275276
*
276277
* @param completion The completion handler to handle the token deletion.
277278
*/
278-
279-
- (void)deleteTokenWithCompletion:(void (^)(NSError *_Nullable error))completion;
279+
- (void)deleteTokenWithCompletion:(void (^NS_SWIFT_UI_ACTOR)(NSError *_Nullable error))completion
280+
NS_SWIFT_UI_ACTOR;
280281

281282
/**
282283
* Retrieves an FCM registration token for a particular Sender ID. This can be used to allow
@@ -298,9 +299,9 @@ NS_SWIFT_NAME(Messaging)
298299
* @param completion The completion handler to handle the token request.
299300
*/
300301
- (void)retrieveFCMTokenForSenderID:(NSString *)senderID
301-
completion:(void (^)(NSString *_Nullable FCMToken,
302-
NSError *_Nullable error))completion
303-
NS_SWIFT_NAME(retrieveFCMToken(forSenderID:completion:));
302+
completion:(void (^NS_SWIFT_UI_ACTOR)(NSString *_Nullable FCMToken,
303+
NSError *_Nullable error))completion
304+
NS_SWIFT_NAME(retrieveFCMToken(forSenderID:completion:)) NS_SWIFT_UI_ACTOR;
304305

305306
/**
306307
* Invalidates an FCM token for a particular Sender ID. That Sender ID cannot no longer send
@@ -311,8 +312,8 @@ NS_SWIFT_NAME(Messaging)
311312
* @param completion The completion handler to handle the token deletion.
312313
*/
313314
- (void)deleteFCMTokenForSenderID:(NSString *)senderID
314-
completion:(void (^)(NSError *_Nullable error))completion
315-
NS_SWIFT_NAME(deleteFCMToken(forSenderID:completion:));
315+
completion:(void (^NS_SWIFT_UI_ACTOR)(NSError *_Nullable error))completion
316+
NS_SWIFT_NAME(deleteFCMToken(forSenderID:completion:)) NS_SWIFT_UI_ACTOR;
316317

317318
#pragma mark - Topics
318319

@@ -323,7 +324,7 @@ NS_SWIFT_NAME(Messaging)
323324
*
324325
* @param topic The name of the topic, for example, @"sports".
325326
*/
326-
- (void)subscribeToTopic:(NSString *)topic NS_SWIFT_NAME(subscribe(toTopic:));
327+
- (void)subscribeToTopic:(NSString *)topic NS_SWIFT_NAME(subscribe(toTopic:)) NS_SWIFT_UI_ACTOR;
327328

328329
/**
329330
* Asynchronously subscribe to the provided topic, retrying on failure. This uses the default FCM
@@ -337,7 +338,8 @@ NS_SWIFT_NAME(Messaging)
337338
* appropriate error object is returned.
338339
*/
339340
- (void)subscribeToTopic:(nonnull NSString *)topic
340-
completion:(void (^_Nullable)(NSError *_Nullable error))completion;
341+
completion:(void (^_Nullable NS_SWIFT_UI_ACTOR)(NSError *_Nullable error))completion
342+
NS_SWIFT_UI_ACTOR;
341343

342344
/**
343345
* Asynchronously unsubscribe from a topic. This uses a FCM Token
@@ -346,7 +348,8 @@ NS_SWIFT_NAME(Messaging)
346348
*
347349
* @param topic The name of the topic, for example @"sports".
348350
*/
349-
- (void)unsubscribeFromTopic:(NSString *)topic NS_SWIFT_NAME(unsubscribe(fromTopic:));
351+
- (void)unsubscribeFromTopic:(NSString *)topic
352+
NS_SWIFT_NAME(unsubscribe(fromTopic:)) NS_SWIFT_UI_ACTOR;
350353

351354
/**
352355
* Asynchronously unsubscribe from the provided topic, retrying on failure. This uses a FCM Token
@@ -359,7 +362,9 @@ NS_SWIFT_NAME(Messaging)
359362
* appropriate error object is returned.
360363
*/
361364
- (void)unsubscribeFromTopic:(nonnull NSString *)topic
362-
completion:(void (^_Nullable)(NSError *_Nullable error))completion;
365+
completion:
366+
(void (^_Nullable NS_SWIFT_UI_ACTOR)(NSError *_Nullable error))completion
367+
NS_SWIFT_UI_ACTOR;
363368

364369
#pragma mark - Analytics
365370

@@ -374,7 +379,7 @@ NS_SWIFT_NAME(Messaging)
374379
*
375380
* @return Information about the downstream message.
376381
*/
377-
- (FIRMessagingMessageInfo *)appDidReceiveMessage:(NSDictionary *)message;
382+
- (FIRMessagingMessageInfo *)appDidReceiveMessage:(NSDictionary *)message NS_SWIFT_UI_ACTOR;
378383

379384
#pragma mark - GDPR
380385
/**
@@ -387,7 +392,8 @@ NS_SWIFT_NAME(Messaging)
387392
* @param completion A completion handler which is invoked when the operation completes. `error ==
388393
* nil` indicates success.
389394
*/
390-
- (void)deleteDataWithCompletion:(void (^)(NSError *__nullable error))completion;
395+
- (void)deleteDataWithCompletion:(void (^NS_SWIFT_UI_ACTOR)(NSError *__nullable error))completion
396+
NS_SWIFT_UI_ACTOR;
391397

392398
@end
393399

FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessagingExtensionHelper.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ NS_ASSUME_NONNULL_BEGIN
3030
/// specified in the notification body via the `image` parameter. Images and other
3131
/// rich content can be populated manually without the use of this class. See the
3232
/// `UNNotificationServiceExtension` type for more details.
33-
__OSX_AVAILABLE(10.14) @interface FIRMessagingExtensionHelper : NSObject
33+
__OSX_AVAILABLE(10.14) NS_SWIFT_SENDABLE @interface FIRMessagingExtensionHelper : NSObject
3434

3535
/// Call this API to complete your notification content modification. If you like to
3636
/// overwrite some properties of the content instead of using the default payload,
37-
/// make sure to make your customized motification to the content before passing it to
38-
/// this call.
39-
- (void)populateNotificationContent:(UNMutableNotificationContent *)content
40-
withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler;
37+
/// make sure to make your customized modification to the content before passing it to
38+
/// this call. The content returned in the content handler after populating will be a
39+
/// different instance than the value passed in to `content`.
40+
- (void)populateNotificationContent:(UNNotificationContent *)content
41+
withContentHandler:
42+
(void (^NS_SWIFT_SENDABLE)(UNNotificationContent *_Nonnull))contentHandler
43+
NS_SWIFT_SENDABLE;
4144

4245
/// Exports delivery metrics to BigQuery. Call this API to enable logging delivery of alert
4346
/// notification or background notification and export to BigQuery.

0 commit comments

Comments
 (0)