Skip to content

Commit 2dff64d

Browse files
committed
Merge pull request #860 from ParsePlatform/nlutsenko.installationAsync
Make loading of installationIdentifier from disk fully async.
2 parents e5eb9c3 + 5bba424 commit 2dff64d

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

Parse/Internal/Installation/CurrentInstallationController/PFCurrentInstallationController.m

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,33 @@ - (BFTask *)getCurrentObjectAsync {
100100
return nil;
101101
}] continueWithBlock:^id(BFTask *task) {
102102
@strongify(self);
103-
if (task.faulted) {
104-
return task;
105-
}
106103

107-
PFInstallation *installation = task.result;
108-
//TODO: (nlutsenko) Make it not terrible aka actually use task chaining here.
109-
NSString *installationId = [[self.installationIdentifierStore getInstallationIdentifierAsync] waitForResult:nil];
110-
installationId = installationId.lowercaseString;
111-
if (!installation || ![installationId isEqualToString:installation.installationId]) {
112-
// If there's no installation object, or the object's installation
113-
// ID doesn't match this device's installation ID, create a new
114-
// installation. Try to keep track of the previously stored device
115-
// token: if there was an installation already stored just re-use
116-
// its device token, otherwise try loading from the keychain (where
117-
// old SDKs stored the token). Discard the old installation.
118-
NSString *oldDeviceToken = nil;
119-
if (installation) {
120-
oldDeviceToken = installation.deviceToken;
121-
} else {
122-
oldDeviceToken = [[PFPush pushInternalUtilClass] getDeviceTokenFromKeychain];
123-
}
104+
__block PFInstallation *installation = task.result;
105+
return [[self.installationIdentifierStore getInstallationIdentifierAsync] continueWithBlock:^id _Nullable(BFTask<NSString *> * _Nonnull task) {
106+
NSString *installationId = task.result.lowercaseString;
107+
if (!installation || ![installationId isEqualToString:installation.installationId]) {
108+
// If there's no installation object, or the object's installation
109+
// ID doesn't match this device's installation ID, create a new
110+
// installation. Try to keep track of the previously stored device
111+
// token: if there was an installation already stored just re-use
112+
// its device token, otherwise try loading from the keychain (where
113+
// old SDKs stored the token). Discard the old installation.
114+
NSString *oldDeviceToken = nil;
115+
if (installation) {
116+
oldDeviceToken = installation.deviceToken;
117+
} else {
118+
oldDeviceToken = [[PFPush pushInternalUtilClass] getDeviceTokenFromKeychain];
119+
}
124120

125-
installation = [PFInstallation object];
126-
installation.deviceType = kPFDeviceType;
127-
installation.installationId = installationId;
128-
if (oldDeviceToken) {
129-
installation.deviceToken = oldDeviceToken;
121+
installation = [PFInstallation object];
122+
installation.deviceType = kPFDeviceType;
123+
installation.installationId = installationId;
124+
if (oldDeviceToken) {
125+
installation.deviceToken = oldDeviceToken;
126+
}
130127
}
131-
}
132-
133-
return installation;
128+
return installation;
129+
}];
134130
}] continueWithBlock:^id(BFTask *task) {
135131
dispatch_barrier_sync(_dataQueue, ^{
136132
_currentInstallation = task.result;

0 commit comments

Comments
 (0)