Skip to content

Commit e4456c0

Browse files
Enables Firebase Messaging push notification function on watch only and independent watch app (#4016)
1 parent e118f2c commit e4456c0

36 files changed

+199
-76
lines changed

.travis.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,22 @@ jobs:
370370
env:
371371
- PROJECT=GoogleUtilities METHOD=pod-lib-lint
372372
script:
373-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb GoogleUtilities.podspec
373+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --platforms=ios
374+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --platforms=tvos
375+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --platforms=macos
374376

375377
- stage: test
376378
if: type = cron
377379
env:
378380
- PROJECT=GoogleUtilitiesCron METHOD=pod-lib-lint
379381
script:
380382

381-
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-libraries
382-
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-modular-headers
383+
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-libraries --platforms=ios
384+
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-libraries --platforms=tvos
385+
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-libraries --platforms=macos
386+
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-modular-headers --platforms=ios
387+
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-modular-headers --platforms=tvos
388+
- travis_retry ./scripts/pod_lib_lint.rb GoogleUtilities.podspec --use-modular-headers --platforms=macos
383389

384390
- stage: test
385391
env:

Example/Messaging/Tests/FIRMessagingInstanceTest.swift

-16
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ class FIRMessagingInstanceTest: XCTestCase {
2727
FirebaseApp.configure(options: options)
2828
letoriginal=Messaging.messaging()
2929

30-
// Ensure the client is set up as expected.
31-
guardlet isOrigClientSetup = original.value(forKey:"isClientSetup")as?Boolelse{
32-
XCTFail("Could not get internal Messaging variable `isClientSetup`.")
33-
return
34-
}
35-
36-
XCTAssertTrue(isOrigClientSetup,"Property `isClientSetup` should be true after creation.")
37-
3830
// Get and delete the default app.
3931
guardlet defaultApp =FirebaseApp.app()else{
4032
XCTFail("Default app was not configured properly.")
@@ -54,13 +46,5 @@ class FIRMessagingInstanceTest: XCTestCase {
5446
// Get another instance of Messaging, make sure it's not the same instance.
5547
letpostDelete=Messaging.messaging()
5648
XCTAssertNotEqual(original, postDelete)
57-
58-
// Ensure the new client is set up as expected.
59-
guardlet isClientSetup = postDelete.value(forKey:"isClientSetup")as?Boolelse{
60-
XCTFail("Could not get internal Messaging variable `isClientSetup`.")
61-
return
62-
}
63-
64-
XCTAssertTrue(isClientSetup,"Property `isClientSetup` should be true after creation.")
6549
}
6650
}

Firebase/Core/FIRApp.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -887,16 +887,16 @@ - (void)sendLogsWithServiceName:(NSString *)serviceName
887887
- (void)subscribeForAppDidBecomeActiveNotifications {
888888
#if TARGET_OS_IOS || TARGET_OS_TV
889889
NSNotificationName notificationName = UIApplicationDidBecomeActiveNotification;
890-
#endif
891-
892-
#if TARGET_OS_OSX
890+
#elif TARGET_OS_OSX
893891
NSNotificationName notificationName = NSApplicationDidBecomeActiveNotification;
894892
#endif
895893

894+
#if !TARGET_OS_WATCH
896895
[[NSNotificationCenterdefaultCenter] addObserver:self
897896
selector:@selector(appDidBecomeActive:)
898897
name:notificationName
899898
object:nil];
899+
#endif
900900
}
901901

902902
- (void)appDidBecomeActive:(NSNotification *)notification {

Firebase/InstanceID/FIRInstanceID.m

+9-11
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@
6060
// change.
6161
NSIntegerconstkMaxRetryCountForDefaultToken = 5;
6262

63-
#if TARGET_OS_IOS || TARGET_OS_TV
63+
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
6464
staticNSString *constkEntitlementsAPSEnvironmentKey = @"Entitlements.aps-environment";
6565
#else
66-
staticNSString *constkEntitlementsAPSEnvironmentKey = @"com.apple.developer.aps-environment";
66+
staticNSString *constkEntitlementsAPSEnvironmentKey =
67+
@"Entitlements.com.apple.developer.aps-environment";
6768
#endif
68-
staticNSString *constkEntitlementsKeyForMac = @"Entitlements";
6969
staticNSString *constkAPSEnvironmentDevelopmentValue = @"development";
7070
/// FIRMessaging selector that returns the current FIRMessaging auto init
7171
/// enabled flag.
@@ -617,10 +617,14 @@ - (void)configureInstanceIDWithOptions:(FIROptions *)options {
617617
[selfupdateFirebaseInstallationID];
618618

619619
// FCM generates a FCM token during app start for sending push notification to device.
620-
// This is not needed for app extension.
620+
// This is not needed for app extension except for watch.
621+
#if TARGET_OS_WATCH
622+
[selfdidCompleteConfigure];
623+
#else
621624
if (![GULAppEnvironmentUtil isAppExtension]) {
622625
[selfdidCompleteConfigure];
623626
}
627+
#endif
624628
}
625629

626630
// This is used to start any operations when we receive FirebaseSDK setup notification
@@ -978,7 +982,7 @@ - (BOOL)isProductionApp {
978982
// Apps distributed via AppStore or TestFlight use the Production APNS certificates.
979983
return defaultAppTypeProd;
980984
}
981-
#if TARGET_OS_IOS || TARGET_OS_TV
985+
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
982986
NSString *path = [[[NSBundlemainBundle] bundlePath]
983987
stringByAppendingPathComponent:@"embedded.mobileprovision"];
984988
#elif TARGET_OS_OSX
@@ -1061,13 +1065,7 @@ - (BOOL)isProductionApp {
10611065
@"most likely a Dev profile.");
10621066
}
10631067

1064-
#if TARGET_OS_IOS || TARGET_OS_TV
10651068
NSString *apsEnvironment = [plistMap valueForKeyPath:kEntitlementsAPSEnvironmentKey];
1066-
#elif TARGET_OS_OSX
1067-
NSDictionary *entitlements = [plistMap valueForKey:kEntitlementsKeyForMac];
1068-
NSString *apsEnvironment = [entitlements valueForKey:kEntitlementsAPSEnvironmentKey];
1069-
#endif
1070-
10711069
NSString *debugString __unused =
10721070
[NSStringstringWithFormat:@"APNS Environment in profile: %@", apsEnvironment];
10731071
FIRInstanceIDLoggerDebug(kFIRInstanceIDMessageCodeInstanceID013, @"%@", debugString);

Firebase/InstanceID/FIRInstanceIDAuthKeyChain.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ - (NSMutableDictionary *)keychainQueryForService:(NSString *)service account:(NS
9191
// FIRInstanceIDKeychain should only take a query and return a result, will handle the query here.
9292
NSArray *passwordInfos =
9393
CFBridgingRelease([[FIRInstanceIDKeychain sharedInstance] itemWithQuery:keychainQuery]);
94-
#elif TARGET_OS_OSX
94+
#elif TARGET_OS_OSX || TARGET_OS_WATCH
9595
keychainQuery[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitOne;
9696
NSData *passwordInfos =
9797
CFBridgingRelease([[FIRInstanceIDKeychain sharedInstance] itemWithQuery:keychainQuery]);
@@ -120,7 +120,7 @@ - (NSMutableDictionary *)keychainQueryForService:(NSString *)service account:(NS
120120
[results addObject:passwordInfo[(__bridge id)kSecValueData]];
121121
}
122122
}
123-
#elif TARGET_OS_OSX
123+
#elif TARGET_OS_OSX || TARGET_OS_WATCH
124124
[results addObject:passwordInfos];
125125
#endif
126126
// We query the keychain because it didn't exist in cache, now query is done, update the result in

Firebase/InstanceID/FIRInstanceIDUtilities.m

+18-5
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,29 @@ int64_t FIRInstanceIDCurrentTimestampInMilliseconds() {
7878
return version;
7979
}
8080

81+
NSString *FIRInstanceIDBundleIDByRemovingLastPartFrom(NSString *bundleID) {
82+
NSString *bundleIDComponentsSeparator = @".";
83+
84+
NSMutableArray<NSString *> *bundleIDComponents =
85+
[[bundleID componentsSeparatedByString:bundleIDComponentsSeparator] mutableCopy];
86+
[bundleIDComponents removeLastObject];
87+
88+
return [bundleIDComponents componentsJoinedByString:bundleIDComponentsSeparator];
89+
}
90+
8191
NSString *FIRInstanceIDAppIdentifier() {
82-
NSString *bundleIdentifier = [[NSBundlemainBundle] bundleIdentifier];
83-
if (!bundleIdentifier.length) {
92+
NSString *bundleID = [[NSBundlemainBundle] bundleIdentifier];
93+
if (!bundleID.length) {
8494
FIRInstanceIDLoggerError(kFIRInstanceIDMessageCodeUtilitiesMissingBundleIdentifier,
8595
@"The mainBundle's bundleIdentifier returned '%@'. Bundle identifier "
8696
@"expected to be non-empty.",
87-
bundleIdentifier);
97+
bundleID);
8898
return@"";
8999
}
90-
return bundleIdentifier;
100+
#if TARGET_OS_WATCH
101+
returnFIRInstanceIDBundleIDByRemovingLastPartFrom(bundleID);
102+
#endif
103+
return bundleID;
91104
}
92105

93106
NSString *FIRInstanceIDFirebaseAppID() {
@@ -111,7 +124,7 @@ int64_t FIRInstanceIDCurrentTimestampInMilliseconds() {
111124
NSString *FIRInstanceIDOperatingSystemVersion() {
112125
#if TARGET_OS_IOS || TARGET_OS_TV
113126
return [UIDevice currentDevice].systemVersion;
114-
#elif TARGET_OS_OSX
127+
#elif TARGET_OS_OSX || TARGET_OS_WATCH
115128
return [NSProcessInfoprocessInfo].operatingSystemVersionString;
116129
#endif
117130
}

Firebase/Messaging/FIRMessaging.m

+6-7
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ @interface FIRMessaging ()<FIRMessagingClientDelegate, FIRMessagingReceiverDeleg
145145

146146
@property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
147147

148-
@property(nonatomic, readwrite, assign) BOOL isClientSetup;
149-
150148
@property(nonatomic, readwrite, strong) FIRMessagingClient *client;
151149
@property(nonatomic, readwrite, strong) GULReachabilityChecker *reachability;
152150
@property(nonatomic, readwrite, strong) FIRMessagingDataMessageManager *dataMessageManager;
@@ -270,6 +268,10 @@ - (void)configureNotificationSwizzlingIfEnabled {
270268
}
271269

272270
- (void)start {
271+
[selfsetupFileManagerSubDirectory];
272+
[selfsetupNotificationListeners];
273+
274+
#if !TARGET_OS_WATCH
273275
// Print the library version for logging.
274276
NSString *currentLibraryVersion = FIRMessagingCurrentLibraryVersion();
275277
FIRMessagingLoggerInfo(kFIRMessagingMessageCodeMessagingPrintLibraryVersion,
@@ -283,16 +285,14 @@ - (void)start {
283285
withHost:hostname];
284286
[self.reachability start];
285287

286-
[selfsetupFileManagerSubDirectory];
287288
// setup FIRMessaging objects
288289
[selfsetupRmqManager];
289290
[selfsetupClient];
290291
[selfsetupSyncMessageManager];
291292
[selfsetupDataMessageManager];
292293
[selfsetupTopics];
293294

294-
self.isClientSetup = YES;
295-
[selfsetupNotificationListeners];
295+
#endif
296296
}
297297

298298
- (void)setupFileManagerSubDirectory {
@@ -373,7 +373,6 @@ - (void)teardown {
373373
self.rmq2Manager = nil;
374374
self.dataMessageManager = nil;
375375
self.client = nil;
376-
self.isClientSetup = NO;
377376
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeMessaging001, @"Did successfully teardown");
378377
}
379378

@@ -687,7 +686,7 @@ - (BOOL)isDirectChannelEstablished {
687686
}
688687

689688
- (BOOL)shouldBeConnectedAutomatically {
690-
#if TARGET_OS_OSX
689+
#if TARGET_OS_OSX || TARGET_OS_WATCH
691690
returnNO;
692691
#else
693692
// We require a token from Instance ID

Firebase/Messaging/FIRMessagingExtensionHelper.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ - (void)populateNotificationContent:(UNMutableNotificationContent *)content
3636
self.bestAttemptContent = content;
3737

3838
// The `userInfo` property isn't available on newer versions of tvOS.
39-
#if TARGET_OS_IOS || TARGET_OS_OSX
39+
#if TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_WATCH
4040
NSString *currentImageURL = content.userInfo[kPayloadOptionsName][kPayloadOptionsImageURLName];
4141
if (!currentImageURL) {
4242
[selfdeliverNotification];
@@ -59,7 +59,7 @@ - (void)populateNotificationContent:(UNMutableNotificationContent *)content
5959
#endif
6060
}
6161

62-
#if TARGET_OS_IOS || TARGET_OS_OSX
62+
#if TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_WATCH
6363
- (void)loadAttachmentForURL:(NSURL *)attachmentURL
6464
completionHandler:(void (^)(UNNotificationAttachment *))completionHandler {
6565
__block UNNotificationAttachment *attachment = nil;

Firebase/Messaging/FIRMessagingUtilities.m

+20-1
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,27 @@ int64_t FIRMessagingCurrentTimestampInMilliseconds(void) {
149149
return version;
150150
}
151151

152+
153+
NSString * FIRMessagingBundleIDByRemovingLastPartFrom(NSString *bundleID) {
154+
NSString *bundleIDComponentsSeparator = @".";
155+
156+
NSMutableArray<NSString *> *bundleIDComponents =
157+
[[bundleID componentsSeparatedByString:bundleIDComponentsSeparator] mutableCopy];
158+
[bundleIDComponents removeLastObject];
159+
160+
return [bundleIDComponents componentsJoinedByString:bundleIDComponentsSeparator];
161+
}
162+
152163
NSString *FIRMessagingAppIdentifier(void) {
153-
return [[NSBundlemainBundle] bundleIdentifier];
164+
NSString *bundleID = [[NSBundlemainBundle] bundleIdentifier];
165+
#if TARGET_OS_WATCH
166+
// The code is running in watchKit extension target but the actually bundleID is in the watchKit
167+
// target. So we need to remove the last part of the bundle ID in watchKit extension to match
168+
// the one in watchKit target.
169+
returnFIRMessagingBundleIDByRemovingLastPartFrom(bundleID);
170+
#else
171+
return bundleID;
172+
#endif
154173
}
155174

156175
uint64_tFIRMessagingGetFreeDiskSpaceInMB(void) {

FirebaseAnalyticsInterop.podspec

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Pod::Spec.new do |s|
2424
s.ios.deployment_target='8.0'
2525
s.osx.deployment_target='10.11'
2626
s.tvos.deployment_target='10.0'
27+
s.watchos.deployment_target='6.0'
28+
2729
s.source_files='Interop/Analytics/**/*.h'
2830
s.public_header_files='Interop/Analytics/Public/*.h'
2931
end

FirebaseCore.podspec

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Firebase Core includes FIRApp and FIROptions which provide central configuration
1919
s.ios.deployment_target='8.0'
2020
s.osx.deployment_target='10.11'
2121
s.tvos.deployment_target='10.0'
22+
s.watchos.deployment_target='6.0'
2223

2324
s.cocoapods_version='>= 1.4.0'
2425
s.static_framework=true
@@ -43,6 +44,7 @@ Firebase Core includes FIRApp and FIROptions which provide central configuration
4344
'OTHER_CFLAGS'=>'-fno-autolink'
4445
}
4546
s.test_spec'unit'do |unit_tests|
47+
unit_tests.platforms={:ios=>'8.0',:osx=>'10.11',:tvos=>'10.0'}
4648
unit_tests.source_files='Example/Core/Tests/**/*.[mh]'
4749
unit_tests.requires_app_host=true
4850
unit_tests.dependency'OCMock'

FirebaseCoreDiagnostics.podspec

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ non-Cocoapod integration. This library also respects the Firebase global data co
2121
s.ios.deployment_target='8.0'
2222
s.osx.deployment_target='10.11'
2323
s.tvos.deployment_target='10.0'
24+
s.watchos.deployment_target='6.0'
2425

2526
s.cocoapods_version='>= 1.4.0'
2627
s.static_framework=true
@@ -51,6 +52,7 @@ non-Cocoapod integration. This library also respects the Firebase global data co
5152
s.dependency'nanopb','~> 0.3.901'
5253

5354
s.test_spec'unit'do |unit_tests|
55+
unit_tests.platforms={:ios=>'8.0',:osx=>'10.11',:tvos=>'10.0'}
5456
unit_tests.dependency'GoogleUtilities/UserDefaults','~> 6.2'
5557
unit_tests.dependency'OCMock'
5658
unit_tests.source_files='Example/CoreDiagnostics/Tests/**/*.[mh]'

FirebaseCoreDiagnosticsInterop.podspec

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Pod::Spec.new do |s|
2424
s.ios.deployment_target='8.0'
2525
s.osx.deployment_target='10.11'
2626
s.tvos.deployment_target='10.0'
27+
s.watchos.deployment_target='6.0'
2728
s.source_files='Interop/CoreDiagnostics/**/*.h'
2829
s.public_header_files='Interop/CoreDiagnostics/Public/*.h'
2930
end

FirebaseInstallations.podspec

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Pod::Spec.new do |s|
1919
s.ios.deployment_target='8.0'
2020
s.osx.deployment_target='10.11'
2121
s.tvos.deployment_target='10.0'
22+
s.watchos.deployment_target='6.0'
2223

2324
s.cocoapods_version='>= 1.4.0'
2425
s.static_framework=true
@@ -54,6 +55,7 @@ Pod::Spec.new do |s|
5455
end
5556

5657
s.test_spec'integration'do |int_tests|
58+
int_tests.platforms={:ios=>'8.0',:osx=>'10.11',:tvos=>'10.0'}
5759
int_tests.source_files=base_dir + 'Tests/Integration/**/*.[mh]'
5860
int_tests.resources=base_dir + 'Tests/Resources/**/*'
5961
ifENV['FIS_INTEGRATION_TESTS_REQUIRED'] && ENV['FIS_INTEGRATION_TESTS_REQUIRED'] == '1'then

FirebaseInstallations/Source/Library/IIDMigration/FIRInstallationsIIDTokenStore.m

+3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ - (instancetype)initWithGCMSenderID:(NSString *)GCMSenderID {
8383
unarchiver = [[NSKeyedUnarchiveralloc] initForReadingFromData:data error:&archiverError];
8484
} else {
8585
@try {
86+
#pragma clang diagnostic push
87+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
8688
unarchiver = [[NSKeyedUnarchiveralloc] initForReadingWithData:data];
89+
#pragma clang diagnostic pop
8790
} @catch (NSException *exception) {
8891
archiverError = [FIRInstallationsErrorUtil keyedArchiverErrorWithException:exception];
8992
}

FirebaseInstallations/Source/Library/SecureStorage/FIRSecureStorage.m

+6
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ - (nullable NSData *)archiveDataForObject:(id<NSSecureCoding>)object error:(NSEr
203203
} else {
204204
@try {
205205
NSMutableData *data = [NSMutableDatadata];
206+
#pragma clang diagnostic push
207+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
206208
NSKeyedArchiver *archiver = [[NSKeyedArchiveralloc] initForWritingWithMutableData:data];
209+
#pragma clang diagnostic pop
207210
archiver.requiresSecureCoding = YES;
208211

209212
[archiver encodeObject:object forKey:NSKeyedArchiveRootObjectKey];
@@ -232,7 +235,10 @@ - (nullable id)unarchivedObjectOfClass:(Class)class
232235
}
233236
} else {
234237
@try {
238+
#pragma clang diagnostic push
239+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
235240
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiveralloc] initForReadingWithData:data];
241+
#pragma clang diagnostic pop
236242
unarchiver.requiresSecureCoding = YES;
237243

238244
object = [unarchiver decodeObjectOfClass:class forKey:NSKeyedArchiveRootObjectKey];

0 commit comments

Comments
 (0)
close