iPhone app token session with the backend - iphone

I'm creating an iPhone app with a ROR 3 backend. I'm just wondering about the best practices with regards to user sessions and session tokens. I would like to design the app such that after an initial registration, the user is always logged in. Is this best done by saving the username and password in NSUserDefaults and automatically logging in behind the scenes when the app launches and using the generated token (stored in the delegate?) for all the operations.. and then basically every time the app launches, a new token is generated.
Or, upon the initial registration, save the token in NSUserDefaults and use that token with every launch?
Thank you and best regards!

Related

FCM token update- flutter

For fcm (Firebase Could messaging), We get a token using getToken()
I want to know,
Is the token generate one time
or
Is the token generate every time user login?
The registration token may change when:
The app is restored on a new device
The user uninstalls/reinstall the app
The user clears app data.
More :
Update from Play Store - Token remains same.
When close the application and reopen it - Token remains same.
If you want to call onTokenRefreshed() you should do it manually.
Learn more - https://firebase.google.com/docs/cloud-messaging/android/client
Additionally,
I recommend you should record that token for the user every time your app launches. Then, you don't face any problems.

Handling iCloud user changes

I am wondering what the best way is to detect a changed iCloud user account when the the app was force quit by the user.
When the app is in the background and the user changes their iCloud account, a notification 'CKAccountChanged' is sent by the time the app enters the foreground so it can be handled. OK.
BUT what if the app was force quit by the user?
My approach is to store the user token locally. At the next app launch, the user token is retrieved and checked against the locally saved one.
Is there a "nicer" way?

iOS app needs logged in after iphone restart

May be it will be a too startup question.
We have developed an iPhone application and its uploaded in the Appstore. We have our own login mechanism, facabook login, and twitter login. Our users reporting an issue that, when the app is started and the iphone device is restarted (switched off), the application is also logged out. And users needs to login again. We have checked Facebook app. It keeps logged in when the device is restarted (switched off). We also want to do like that. Can you have suggest mechanism to do like that.
Store the Username and password in the keychain. When the app starts up, then grab the username and password from the keychain and execute the method for login.
John
You can can Store your acessToken (facebook) with NSUserDefaults, CoreData or FileSystem. I will not suggest you to save your login/password inside your app. If you need to do this, its better save data user(name,address,celphone...) but not the access, like login/password. Its more safe. Of course, you can use KeyChain, but will each in what are you thinking doing with the app.
NSUserDefaults
Save string to the NSUserDefaults?
File System - apple guide
http://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/FileSystemOverview/FileSystemOverview.html
Core Data
Save and Load Data - CoreData

Access iOS Keychain from iPhone Settings app

Here is my situation...
I want my password to be encrypted and at the same time I want it to be in iPhone settings (by adding resource and accessing it through NSUserDefaults), but i think NSUserDefaults saves the password or information in plane text and iPhone takes care of everything in its Settings app if there is any change or whatever.
How could I make sure that information that I see in the Settings is coming from and going back to Keychain but before that, Is it possible? If not any other way? May be writing encrypted file?
I DO NOT want settings to be in my app.
thank you
us
The Keychain service cannot be invoked from within Settings, you need to do this within your app. It is good practice to ask users for their password within your app in a login page or UIAlertView at least (like the App Store does).
From the user's point of view, they don't want to have to launch Settings, enter their password, and then launch your app to log in, they want to do it all in one place.

Application session in iOS?

I need to create a "login application" but I don't know about session in iOS. My application need login to my website (PHP based website) to get data. Can anybody tell me how to create and manage application session in iOS app? Thanks!
There's no concept of web/browser session (whatever that means to you) in iOS. iOS applications are just launched when a user touches the icon, and are quit when the user quit them.
Typically you require the user to input the login id and the password when the app is launched, and you create a web/server/browser session by accessing the web server. You can keep the id and the password securely inside in the storage of the iPhone, so that the user doesn't need to input them again and again whenever the program is launched.