function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IanHulmeIanHulme 

iOS SDK - persistent login while Offline

Hi All,

 

I'm building a custom iPad app that will need to be used offline once initiated.

 

I'm using the mobile sdk example as the base, and it logs in fine and the data comes down etc, but I am struggling to find any documentation on checking that the user has previously logged in if no internet conenction is availble.

 

Could anyone point me in the right directions?

 

Many thanks,

Ian

 

 

Kevin HawkinsKevin Hawkins

Are you building a native or hybrid app?

IanHulmeIanHulme

Hi Kevin,

 

Sorry, I'm building a native iOS app...

 

Thanks,

Ian

Kevin HawkinsKevin Hawkins

Are you building your app based on the Native Force.com REST App template?  At this point, the native app template is not offline aware, meaning that the user will get alert notifications when he/she opens the app, it tries to authenticate, and can't because there's no network connection.

 

If you're building an app strictly from the native libraries, where you could control all aspects of authentication, you would want to make use of the SFOAuthCoordinator and its SFOAuthCredentials property, from the SalesforceOAuth library.  The SFOAuthCredentials object can tell you if it has a refreshToken, which would let you know whether or not the user has authenticated in the lifetime of the app.  Note that this isn't a guarantee that the user still has *valid* credentials, but it's a pretty good approximation in the offline case.

 

We will be updating the native template apps in the future to be more offline aware, so that apps will degrade more gracefully (if the developer desires) in the case where there's no connectivity.

 

Cheers,

Kevin

IanHulmeIanHulme

Hi Kevin,

 

Thanks for thw response, I am building it based on the Native Force.com REST App template as I am still trying to understand the code properly.

 

I will look into the use of the SFOAuthCoordinator and its SFOAuthCredentials, does this automatically save the refreshToken to the device? or would it require some more script on logging in to do so?

 

If so, I think it would be quite easy to integrate an offline checker which would then check to see if there was a refresh token.

 

Thanks again for your help with this.

 

Ian

Kevin HawkinsKevin Hawkins

Yes, the SFOAuthCoordinator and related classes will securely store and retrieve the refresh token, so that's something you wouldn't have to worry about.

 

There are certainly many ways you can go to determine offline/online status, whether through Reachability, periodic ping services, or reactive network calls that fall back to offline behavior when calls fail due to no connectivity.  We will probably look at providing some measure of this kind of functionality in the SDK in the future, but its scheduling is uncertain at this point.

 

Cheers,

Kevin

 

IanHulmeIanHulme

Thanks Kevin,

 

That little push helped alot.