Open frmrgr opened 6 years ago
Yeah it looks like Android counterpart does this. I use this module to login into my own backend and then use its credentials, so I didn't have a chance to notice this.
The difference is that iOS needs permissions scope to wake up, and Android obtains it from current access token (if it exists). Therefore, optional permissions
argument should be added to initialize
method of this module. It should be optional to be a non-breaking change, and it's not needed on android anyway. In case if permissions are not provided, iOS bridge should try to get current access token (as android does) and use its permissions to call wakeUpSession
.
This shouldn't be difficult, but I don't have time for this at least until Monday. I can review the PR though.
I think that permissions
argument is unnecesary, since it is only used to check against already present scope and force logout in case something is missing. Long story short, passing empty array should be just fine if the purpose is to just check whether user is logged. So basically, as I see it, it would be
[VKSdk wakeUpSession:@[] completeBlock:^(VKAuthorizationState state, NSError *error) {
if (error)
reject(error);
else
resolve([NSNumber numberWithBool:[VKSdk isLoggedIn]]);
}
Sorry, I don't wanna do PR since I am not objc programmer.
Yeah you're right, it's ok to call wakeUpSession
with empty array. But semantically wakeUpSession
should be called in initialize
, and vk-android-sdk
does so internally. Also isLoggedIn
works similarly in vk-ios-sdk
and vk-android-sdk
.
Then vk-ios-sdk
docs say that wakeUpSession
can result in
VKAuthorizationError - means some error happened when we tried to check the authorization. Probably, the internet connection has a bad quality. You have to try again later.
So I need to check what android does in this situation. So my guess is that it does nothing, and if session is not waken on initialize due to error, then isLoggedIn
is false.
So when I'm going to work on this the plan is:
wakeUpSession
in initialize
fails. Then maybe I'll change my mind about 2 and 3wakeUpSession
should be called on ios initialize
with empty array and with no-op completeBlock.wakeUpSession
should be exposed to JSI just published react-native-vkontakte-login@0.4.0-beta.2
In this version wakeUpSession
is called during initialize
on iOS.
I also added getAccessToken
method.
Please test it.
isLoggedIn
method always resolves withfalse
on ios after app restart despite successful authorization. I do not know much about how sdk works, but it seems thatwakeUpSession
call is required for sdk to restoreaccessToken
. At least, I cannot trace (sdk code) howinitializeWithAppId
(which is the only thing called by this library on app launch) can setvkSdkInstance.accessToken
(which is howisLoggedIn
works) without calling anything else.