E604 The instanceID sync API is deprecated. Implement the async instanceID API by dmandar · Pull Request #3993 · firebase/firebase-ios-sdk · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10BC0
57 changes: 39 additions & 18 deletions FirebaseRemoteConfig/Sources/RCNFetch.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,46 @@ - (void)refreshInstanceIDTokenAndFetchCheckInInfoWithCompletionHandler:
[self fetchCheckinInfoWithCompletionHandler:completionHandler];
return;
}
__weak RCNConfigFetch *weakSelf = self;
FIRInstanceIDTokenHandler instanceIDHandler = ^(NSString *token, NSError *error) {
RCNConfigFetch *instanceIDHandlerSelf = weakSelf;
dispatch_async(instanceIDHandlerSelf->_lockQueue, ^{
RCNConfigFetch *strongSelf = instanceIDHandlerSelf;
if (error) {
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000020",
@"Failed to register InstanceID with error : %@.", error);
}
if (token) {
NSError *IIDError;
strongSelf->_settings.configInstanceIDToken = [token copy];
strongSelf->_settings.configInstanceID = [instanceID appInstanceID:&IIDError];
FIRLogInfo(kFIRLoggerRemoteConfig, @"I-RCN000022", @"Success to get iid : %@.",
strongSelf->_settings.configInstanceID);
}
// Continue the fetch regardless of whether fetch of instance ID succeeded.
[strongSelf fetchCheckinInfoWithCompletionHandler:completionHandler];
});
if (error) {
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000020",
@"Failed to register InstanceID with error : %@.", error);
}

// If the token is available, try to get the instanceID.
__weak RCNConfigFetch *weakSelf = self;
if (token) {
[instanceID getIDWithHandler:^(NSString *_Nullable identity, NSError *_Nullable error) {
RCNConfigFetch *strongSelf = weakSelf;

// Dispatch to the RC serial queue to update settings on the queue.
dispatch_async(strongSelf->_lockQueue, ^{
RCNConfigFetch *strongSelfQueue = weakSelf;

// Update config settings with the IID and token.
strongSelfQueue->_settings.configInstanceIDToken = [token copy];
strongSelfQueue->_settings.configInstanceID = identity;

if (identity && !error) {
FIRLogInfo(kFIRLoggerRemoteConfig, @"I-RCN000022", @"Success to get iid : %@.",
strongSelfQueue->_settings.configInstanceID);
} else {
FIRLogWarning(kFIRLoggerRemoteConfig, @"I-RCN000055", @"Error getting iid : %@.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for !error && !identity? If so, this will crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is..not sure where we would crash though..

error);
}

// Continue the fetch regardless of whether fetch of instance ID succeeded.
[strongSelfQueue fetchCheckinInfoWithCompletionHandler:completionHandler];
});
}];

} else {
dispatch_async(self->_lockQueue, ^{
RCNConfigFetch *strongSelfQueue = weakSelf;
// Continue the fetch regardless of whether fetch of instance ID succeeded.
[strongSelfQueue fetchCheckinInfoWithCompletionHandler:completionHandler];
});
}
};
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000039", @"Starting requesting token.");
// Note: We expect the GCMSenderID to always be available by the time this request is made.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,21 @@ - (void)printResult:(NSMutableString *)output {
[self statusString:currentRCInstance.lastFetchStatus]]];

FIRInstanceID *instanceID = [FIRInstanceID instanceID];
NSError *error;
NSString *instanceIDString = [instanceID appInstanceID:&error];
[output appendString:@"\n-----------Instance ID------------------\n"];
[output appendString:[NSString stringWithFormat:@"%@\n", instanceIDString]];
[instanceID getIDWithHandler:^(NSString *_Nullable identity, NSError *_Nullable error) {
[output appendString:@"\n-----------Instance ID------------------\n"];
[output appendString:[NSString stringWithFormat:@"%@\n", identity]];

[output appendString:@"\n-----------Instance ID token------------\n"];
[output
appendString:[NSString
stringWithFormat:@"%@\n", currentRCInstance.settings.configInstanceIDToken]];
[output appendString:@"\n-----------Instance ID token------------\n"];
[output
appendString:[NSString stringWithFormat:@"%@\n",
currentRCInstance.settings.configInstanceIDToken]];

[output appendString:@"\n-----------Android ID------------\n"];
[output
appendString:[NSString stringWithFormat:@"%@\n", currentRCInstance.settings.deviceAuthID]];
[output appendString:@"\n-----------Android ID------------\n"];
[output
appendString:[NSString stringWithFormat:@"%@\n", currentRCInstance.settings.deviceAuthID]];

[[FRCLog sharedInstance] logToConsole:output];
[[FRCLog sharedInstance] logToConsole:output];
}];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
Expand Down Expand Up @@ -414,12 +414,13 @@ - (IBAction)fetchIIDButtonClicked:(id)sender {
if (token) {
((FIRRemoteConfig *)self.RCInstances[self.currentNamespace][self.FIRAppName])
.settings.configInstanceIDToken = token;
NSString *iid = [instanceID appInstanceID:&error];
[[FRCLog sharedInstance]
logToConsole:
[NSString
stringWithFormat:@"Successfully getting InstanceID : \n\n%@\n\nToken : \n\n%@\n",
iid, token]];
[instanceID getIDWithHandler:^(NSString *_Nullable identity, NSError *_Nullable error) {
[[FRCLog sharedInstance]
logToConsole:[NSString
stringWithFormat:
@"Successfully getting InstanceID : \n\n%@\n\nToken : \n\n%@\n",
identity, token]];
}];
}
};
[instanceID tokenWithAuthorizedEntity:[FIRApp appNamed:self.FIRAppName].options.GCMSenderID
Expand Down
0