Skip to content

Commit 35b001e

Browse files
authored
[Messaging] Refactor Messaging.serviceExtension() API out of FIRMessaging.h (#13723)
1 parent 5632b27 commit 35b001e

File tree

6 files changed

+81
-22
lines changed

6 files changed

+81
-22
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2024 Google LLC
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 "FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessaging+ExtensionHelper.h"
18+
19+
#import "FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessaging.h"
20+
#import "FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessagingExtensionHelper.h"
21+
22+
@implementation FIRMessaging (ExtensionHelper)
23+
24+
+ (FIRMessagingExtensionHelper *)extensionHelper {
25+
static dispatch_once_t once;
26+
static FIRMessagingExtensionHelper *extensionHelper;
27+
dispatch_once(&once, ^{
28+
extensionHelper = [[FIRMessagingExtensionHelper alloc] init];
29+
});
30+
return extensionHelper;
31+
}
32+
33+
/// Stub used to force the linker to include the categories in this file.
34+
void FIRInclude_FIRMessaging_ExtensionHelper_Category(void) {
35+
}
36+
37+
@end

FirebaseMessaging/Sources/FIRMessaging.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#import "FirebaseMessaging/Sources/FIRMessagingUtilities.h"
4141
#import "FirebaseMessaging/Sources/FIRMessaging_Private.h"
4242
#import "FirebaseMessaging/Sources/NSError+FIRMessaging.h"
43-
#import "FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessagingExtensionHelper.h"
4443
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthService.h"
4544
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.h"
4645
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenManager.h"
@@ -131,14 +130,6 @@ + (FIRMessaging *)messaging {
131130
return (FIRMessaging *)instance;
132131
}
133132

134-
+ (FIRMessagingExtensionHelper *)extensionHelper {
135-
static dispatch_once_t once;
136-
static FIRMessagingExtensionHelper *extensionHelper;
137-
dispatch_once(&once, ^{
138-
extensionHelper = [[FIRMessagingExtensionHelper alloc] init];
139-
});
140-
return extensionHelper;
141-
}
142133
- (instancetype)initWithAnalytics:(nullable id<FIRAnalyticsInterop>)analytics
143134
userDefaults:(GULUserDefaults *)defaults
144135
heartbeatLogger:(FIRHeartbeatLogger *)heartbeatLogger {
@@ -1030,6 +1021,7 @@ + (NSString *)FIRMessagingSDKCurrentLocale {
10301021

10311022
#pragma mark - Force Category Linking
10321023

1024+
extern void FIRInclude_FIRMessaging_ExtensionHelper_Category(void);
10331025
extern void FIRInclude_NSDictionary_FIRMessaging_Category(void);
10341026
extern void FIRInclude_NSError_FIRMessaging_Category(void);
10351027

@@ -1038,8 +1030,8 @@ + (NSString *)FIRMessagingSDKCurrentLocale {
10381030
/// This method forces the linker to include categories even if
10391031
/// users do not include the '-ObjC' linker flag in their project.
10401032
+ (void)noop {
1033+
FIRInclude_FIRMessaging_ExtensionHelper_Category();
10411034
FIRInclude_NSDictionary_FIRMessaging_Category();
10421035
FIRInclude_NSError_FIRMessaging_Category();
10431036
}
1044-
10451037
@end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2024 Google LLC
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+
#import "FIRMessaging.h"
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
@class FIRMessagingExtensionHelper;
24+
25+
@interface FIRMessaging (ExtensionHelper)
26+
27+
/**
28+
* Use the MessagingExtensionHelper to populate rich UI content for your notifications.
29+
* For example, if an image URL is set in your notification payload or on the console,
30+
* you can use the MessagingExtensionHelper instance returned from this method to render
31+
* the image in your notification.
32+
*
33+
* @return An instance of MessagingExtensionHelper that handles the extensions API.
34+
*/
35+
+ (FIRMessagingExtensionHelper *)extensionHelper NS_SWIFT_NAME(serviceExtension());
36+
37+
@end
38+
39+
NS_ASSUME_NONNULL_END

FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessaging.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ NS_SWIFT_NAME(MessagingMessageInfo)
136136
@end
137137

138138
@class FIRMessaging;
139-
@class FIRMessagingExtensionHelper;
140139

141140
/**
142141
* A protocol to handle token update or data message delivery from FCM.
@@ -184,17 +183,6 @@ NS_SWIFT_NAME(Messaging)
184183
*/
185184
+ (instancetype)messaging NS_SWIFT_NAME(messaging());
186185

187-
/**
188-
* Use the MessagingExtensionHelper to populate rich UI content for your notifications.
189-
* For example, if an image URL is set in your notification payload or on the console,
190-
* you can use the MessagingExtensionHelper instance returned from this method to render
191-
* the image in your notification.
192-
*
193-
* @return An instance of MessagingExtensionHelper that handles the extensions API.
194-
*/
195-
+ (FIRMessagingExtensionHelper *)extensionHelper NS_SWIFT_NAME(serviceExtension())
196-
NS_AVAILABLE(10.14, 10.0);
197-
198186
/**
199187
* Unavailable. Use +messaging instead.
200188
*/

FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessagingExtensionHelper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19+
#import "FIRMessaging+ExtensionHelper.h"
20+
1921
@class UNMutableNotificationContent, UNNotificationContent;
2022

2123
#if __has_include(<UserNotifications/UserNotifications.h>)

FirebaseMessaging/Sources/Public/FirebaseMessaging/FirebaseMessaging.h

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17+
#import "FIRMessaging+ExtensionHelper.h"
1718
#import "FIRMessaging.h"
1819
#import "FIRMessagingExtensionHelper.h"

0 commit comments

Comments
 (0)