aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Messaging
diff options
context:
space:
mode:
authorGravatar Morgan Chen <morganchen12@gmail.com>2018-03-27 12:37:27 -0700
committerGravatar Morgan Chen <morganchen12@gmail.com>2018-03-27 12:37:27 -0700
commitc67031386d68b320ce730525399969b20893c8e0 (patch)
tree0bd5250da1e5b42066c94186137f21f3b7a83e17 /Firebase/Messaging
parentcb8c4b6b1f1ad213a5b3272e2c2e94f755bbabf9 (diff)
Remove FIRMessagingInstanceIDProxy
Diffstat (limited to 'Firebase/Messaging')
-rw-r--r--Firebase/Messaging/FIRMessaging.m73
-rw-r--r--Firebase/Messaging/FIRMessagingInstanceIDProxy.h56
-rw-r--r--Firebase/Messaging/FIRMessagingInstanceIDProxy.m123
3 files changed, 50 insertions, 202 deletions
diff --git a/Firebase/Messaging/FIRMessaging.m b/Firebase/Messaging/FIRMessaging.m
index 1cc9a6c..e02a125 100644
--- a/Firebase/Messaging/FIRMessaging.m
+++ b/Firebase/Messaging/FIRMessaging.m
@@ -28,7 +28,6 @@
#import "FIRMessagingContextManagerService.h"
#import "FIRMessagingDataMessageManager.h"
#import "FIRMessagingDefines.h"
-#import "FIRMessagingInstanceIDProxy.h"
#import "FIRMessagingLogger.h"
#import "FIRMessagingPubSub.h"
#import "FIRMessagingReceiver.h"
@@ -38,6 +37,7 @@
#import "FIRMessagingVersionUtilities.h"
#import <FirebaseCore/FIRReachabilityChecker.h>
+#import <FirebaseInstanceID/FirebaseInstanceID.h>
#import "NSError+FIRMessaging.h"
@@ -76,10 +76,25 @@ NSString *const kFIRMessagingUserDefaultsKeyAutoInitEnabled =
static NSString *const kFIRMessagingPlistAutoInitEnabled =
@"FirebaseMessagingAutoInitEnabled"; // Auto Init Enabled key stored in Info.plist
-// Copied from Apple's header in case it is missing in some cases (e.g. pre-Xcode 8 builds).
-#ifndef NSFoundationVersionNumber_iOS_8_x_Max
-#define NSFoundationVersionNumber_iOS_8_x_Max 1199
-#endif
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+/// A private helper to convert enum values without depending on their numerical values
+/// (avoid casting). This can be removed when InstanceID's deprecated APNS type enum is
+/// removed.
+FIRInstanceIDAPNSTokenType FIRIIDAPNSTokenTypeFromAPNSTokenType(FIRMessagingAPNSTokenType type) {
+ switch (type) {
+ case FIRMessagingAPNSTokenTypeProd:
+ return FIRInstanceIDAPNSTokenTypeProd;
+ case FIRMessagingAPNSTokenTypeSandbox:
+ return FIRInstanceIDAPNSTokenTypeSandbox;
+ case FIRMessagingAPNSTokenTypeUnknown:
+ return FIRInstanceIDAPNSTokenTypeUnknown;
+
+ default:
+ return FIRInstanceIDAPNSTokenTypeUnknown;
+ }
+}
+#pragma clang diagnostic pop
@interface FIRMessagingMessageInfo ()
@@ -134,9 +149,7 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
@property(nonatomic, readwrite, strong) NSData *apnsTokenData;
@property(nonatomic, readwrite, strong) NSString *defaultFcmToken;
-// This object is used as a proxy for reflection-based calls to FIRInstanceID.
-// Due to our packaging requirements, we can't directly depend on FIRInstanceID currently.
-@property(nonatomic, readwrite, strong) FIRMessagingInstanceIDProxy *instanceIDProxy;
+@property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
@property(nonatomic, readwrite, assign) BOOL isClientSetup;
@@ -154,6 +167,9 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
/// calling it implicitly during swizzling.
@property(nonatomic, readwrite, strong) NSMutableSet *loggedMessageIDs;
+- (instancetype)initWithInstanceID:(FIRInstanceID *)instanceID
+ userDefaults:(NSUserDefaults *)defaults NS_DESIGNATED_INITIALIZER;
+
@end
@implementation FIRMessaging
@@ -168,16 +184,22 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
return messaging;
}
-- (instancetype)initPrivately {
+- (instancetype)initWithInstanceID:(FIRInstanceID *)instanceID
+ userDefaults:(NSUserDefaults *)defaults {
self = [super init];
- if (self) {
+ if (self != nil) {
_loggedMessageIDs = [NSMutableSet set];
- _instanceIDProxy = [[FIRMessagingInstanceIDProxy alloc] init];
- _messagingUserDefaults = [NSUserDefaults standardUserDefaults];
+ _instanceID = instanceID;
+ _messagingUserDefaults = defaults;
}
return self;
}
+- (instancetype)initPrivately {
+ return [self initWithInstanceID:[FIRInstanceID instanceID]
+ userDefaults:[NSUserDefaults standardUserDefaults]];
+}
+
- (void)dealloc {
[self.reachability stop];
[[NSNotificationCenter defaultCenter] removeObserver:self];
@@ -454,7 +476,12 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
return;
}
self.apnsTokenData = apnsToken;
- [self.instanceIDProxy setAPNSToken:apnsToken type:(FIRMessagingInstanceIDProxyAPNSTokenType)type];
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ [self.instanceID setAPNSToken:apnsToken
+ type:FIRIIDAPNSTokenTypeFromAPNSTokenType(type)];
+#pragma clang diagnostic pop
}
#pragma mark - FCM
@@ -482,7 +509,7 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
[_messagingUserDefaults setBool:autoInitEnabled
forKey:kFIRMessagingUserDefaultsKeyAutoInitEnabled];
if (!isFCMAutoInitEnabled && autoInitEnabled) {
- self.defaultFcmToken = [self.instanceIDProxy token];
+ self.defaultFcmToken = self.instanceID.token;
}
}
@@ -490,7 +517,7 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
NSString *token = self.defaultFcmToken;
if (!token) {
// We may not have received it from Instance ID yet (via NSNotification), so extract it directly
- token = [self.instanceIDProxy token];
+ token = self.instanceID.token;
}
return token;
}
@@ -520,10 +547,10 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
@"Be sure to re-retrieve the FCM token once the APNS device token is "
@"set.", senderID);
}
- [self.instanceIDProxy tokenWithAuthorizedEntity:senderID
- scope:kFIRMessagingDefaultTokenScope
- options:options
- handler:completion];
+ [self.instanceID tokenWithAuthorizedEntity:senderID
+ scope:kFIRMessagingDefaultTokenScope
+ options:options
+ handler:completion];
}
- (void)deleteFCMTokenForSenderID:(nonnull NSString *)senderID
@@ -540,9 +567,9 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
}
return;
}
- [self.instanceIDProxy deleteTokenWithAuthorizedEntity:senderID
- scope:kFIRMessagingDefaultTokenScope
- handler:completion];
+ [self.instanceID deleteTokenWithAuthorizedEntity:senderID
+ scope:kFIRMessagingDefaultTokenScope
+ handler:completion];
}
#pragma mark - FIRMessagingDelegate helper methods
@@ -851,7 +878,7 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
- (void)defaultInstanceIDTokenWasRefreshed:(NSNotification *)notification {
// Retrieve the Instance ID default token, and if it is non-nil, post it
- NSString *token = [self.instanceIDProxy token];
+ NSString *token = self.instanceID.token;
// Sometimes Instance ID doesn't yet have a token, so wait until the default
// token is fetched, and then notify. This ensures that this token should not
// be nil when the developer accesses it.
diff --git a/Firebase/Messaging/FIRMessagingInstanceIDProxy.h b/Firebase/Messaging/FIRMessagingInstanceIDProxy.h
deleted file mode 100644
index b7ebd4b..0000000
--- a/Firebase/Messaging/FIRMessagingInstanceIDProxy.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#import <Foundation/Foundation.h>
-
-typedef void(^FIRMessagingInstanceIDProxyTokenHandler)(NSString * __nullable token,
- NSError * __nullable error);
-
-typedef void(^FIRMessagingInstanceIDProxyDeleteTokenHandler)(NSError * __nullable error);
-
-typedef NS_ENUM(NSInteger, FIRMessagingInstanceIDProxyAPNSTokenType) {
- /// Unknown token type.
- FIRMessagingInstanceIDProxyAPNSTokenTypeUnknown,
- /// Sandbox token type.
- FIRMessagingInstanceIDProxyAPNSTokenTypeSandbox,
- /// Production token type.
- FIRMessagingInstanceIDProxyAPNSTokenTypeProd,
-};
-
-/**
- * FIRMessaging cannot always depend on FIRInstanceID directly, due to how FIRMessaging is
- * packaged. To make it easier to make calls to FIRInstanceID, this proxy class, will provide
- * method names duplicated from FIRInstanceID, while using reflection-based called to proxy
- * the requests.
- */
-@interface FIRMessagingInstanceIDProxy : NSObject
-
-- (void)setAPNSToken:(nonnull NSData *)token type:(FIRMessagingInstanceIDProxyAPNSTokenType)type;
-
-#pragma mark - Tokens
-
-- (nullable NSString *)token;
-
-- (void)tokenWithAuthorizedEntity:(nonnull NSString *)authorizedEntity
- scope:(nonnull NSString *)scope
- options:(nullable NSDictionary *)options
- handler:(nonnull FIRMessagingInstanceIDProxyTokenHandler)handler;
-
-- (void)deleteTokenWithAuthorizedEntity:(nonnull NSString *)authorizedEntity
- scope:(nonnull NSString *)scope
- handler:
- (nonnull FIRMessagingInstanceIDProxyDeleteTokenHandler)handler;
-@end
diff --git a/Firebase/Messaging/FIRMessagingInstanceIDProxy.m b/Firebase/Messaging/FIRMessagingInstanceIDProxy.m
deleted file mode 100644
index 01b4e73..0000000
--- a/Firebase/Messaging/FIRMessagingInstanceIDProxy.m
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#import "FIRMessagingInstanceIDProxy.h"
-
-@implementation FIRMessagingInstanceIDProxy
-
-+ (nonnull instancetype)instanceIDProxy {
- static id proxyInstanceID = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- Class instanceIDClass = NSClassFromString(@"FIRInstanceID");
- if (!instanceIDClass) {
- proxyInstanceID = nil;
- return;
- }
- SEL instanceIDSelector = NSSelectorFromString(@"instanceID");
- if (![instanceIDClass respondsToSelector:instanceIDSelector]) {
- proxyInstanceID = nil;
- return;
- }
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
- proxyInstanceID = [instanceIDClass performSelector:instanceIDSelector];
-#pragma clang diagnostic pop
- });
- return (FIRMessagingInstanceIDProxy *)proxyInstanceID;
-
-}
-
-- (void)setAPNSToken:(nonnull NSData *)token
- type:(FIRMessagingInstanceIDProxyAPNSTokenType)type {
- id proxy = [[self class] instanceIDProxy];
-
- SEL setAPNSTokenSelector = NSSelectorFromString(@"setAPNSToken:type:");
- if (![proxy respondsToSelector:setAPNSTokenSelector]) {
- return;
- }
- // Since setAPNSToken takes a scalar value, use NSInvocation
- NSMethodSignature *methodSignature =
- [[proxy class] instanceMethodSignatureForSelector:setAPNSTokenSelector];
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
- invocation.selector = setAPNSTokenSelector;
- invocation.target = proxy;
- [invocation setArgument:&token atIndex:2];
- [invocation setArgument:&type atIndex:3];
- [invocation invoke];
-}
-
-#pragma mark - Tokens
-
-- (nullable NSString *)token {
- id proxy = [[self class] instanceIDProxy];
- SEL getTokenSelector = NSSelectorFromString(@"token");
- if (![proxy respondsToSelector:getTokenSelector]) {
- return nil;
- }
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
- return [proxy performSelector:getTokenSelector];
-#pragma clang diagnostic pop
-}
-
-
-- (void)tokenWithAuthorizedEntity:(nonnull NSString *)authorizedEntity
- scope:(nonnull NSString *)scope
- options:(nullable NSDictionary *)options
- handler:(nonnull FIRMessagingInstanceIDProxyTokenHandler)handler {
-
- id proxy = [[self class] instanceIDProxy];
- SEL getTokenSelector = NSSelectorFromString(@"tokenWithAuthorizedEntity:scope:options:handler:");
- if (![proxy respondsToSelector:getTokenSelector]) {
- return;
- }
- // Since there are >2 arguments, use NSInvocation
- NSMethodSignature *methodSignature =
- [[proxy class] instanceMethodSignatureForSelector:getTokenSelector];
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
- invocation.selector = getTokenSelector;
- invocation.target = proxy;
- [invocation setArgument:&authorizedEntity atIndex:2];
- [invocation setArgument:&scope atIndex:3];
- [invocation setArgument:&options atIndex:4];
- [invocation setArgument:&handler atIndex:5];
- [invocation invoke];
-}
-
-- (void)deleteTokenWithAuthorizedEntity:(nonnull NSString *)authorizedEntity
- scope:(nonnull NSString *)scope
- handler:
- (nonnull FIRMessagingInstanceIDProxyDeleteTokenHandler)handler {
-
- id proxy = [[self class] instanceIDProxy];
- SEL deleteTokenSelector = NSSelectorFromString(@"deleteTokenWithAuthorizedEntity:scope:handler:");
- if (![proxy respondsToSelector:deleteTokenSelector]) {
- return;
- }
- // Since there are >2 arguments, use NSInvocation
- NSMethodSignature *methodSignature =
- [[proxy class] instanceMethodSignatureForSelector:deleteTokenSelector];
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
- invocation.selector = deleteTokenSelector;
- invocation.target = proxy;
- [invocation setArgument:&authorizedEntity atIndex:2];
- [invocation setArgument:&scope atIndex:3];
- [invocation setArgument:&handler atIndex:4];
- [invocation invoke];
-}
-
-@end