Is there a way to get the date when the user downloaded / installed the first time an app via Facebook ? In my app , in the first launch you have to connect with Facebook. So I wonder , is there a way to get the date of this first connection.
I found nothing interesting during my research on internet..
Thanks !
Here is multiple way to do this.
1.> You can store it on server end along with device UUID at login time.When you login first time with facebook via a remote connection , at server end you can put a check that this UUID is aready exist or not. If it is not then you can insert this UUID along with current date and time into server end database.
2.> You can store it locally in NSUserDefaults . Whenever you login with facebook , just check NSUserDefaults value via this code
if (![[NSUserDefaults standardUserDefaults] valueForKey:#"firstTimeFaceBookLogin"])
{
[[NSUserDefaults standardUserDefaults] setValue:[NSDate date] forKey:#"firstTimeFaceBookLogin"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
NSLog(#"current date ===%#",[[NSUserDefaults standardUserDefaults] valueForKey:#"firstTimeFaceBookLogin"]);
Now NSUserDefaults value any where in your app via firstTimeFaceBookLogin key. But if you delete your application from device then this NSUserDefaults would be clear and again create a store new value after installing it in your device.
I hope you understand it. Please let me inform if you still having any confusion. Thanks
Related
This is how it is accomplished in my app:
I keep the data in iCloud.
I need to do some time consuming thing for users who already used my app. But this will also start for completely new users... they just downloaded my app from AppStore for the first time. And this is not expected.
How can I determine that the app is running, but downloaded from AppStore for the first time?
What I could do, but I did not:
put any boolean data in the Keychain, and then check if it exists.
Since you have no non-app end to distinguish users Keychain as you mentioned is your only app persistance option that will survive app uninstalling. Only device Reset to factory settings would remove it.
you can use NSUserDefaults . if appDelegate.m ->didFinishLaunchingWithOptions use this code :
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults objectForKey:#"first_time"] == nil){
[userDefaults setObject:#"1" forKey:#"first_time"];
//do whatever you need
}
this condition will satisfied only once after installation .
After successfully login with services call, I am showing dashboard into my application, there we have another service calls.
Problem is after running time application and then killing the app thread the link between app and services call is collapsed.
How to maintain that user is already logged if he/she login into application and kills the app. (Killing app double click home button and swipe up the app).
Do I have to call same login services on application did finished launch.
or check the user already login
My Question here is maintaining Session for accessing other services. But from server side its always says user is not login In after killing app from back ground.
#All
Your info helpful in make for integration services.
Thanks In Advance.
You can set a BOOL value to NSNumber object and add it to NSUserDefault when the login finish.
NSUserDefaults *boolUserDefaults = [NSUserDefaults standardUserDefaults];
[boolUserDefaults setObject:[NSNumber numberWithBool:YES]
forKey:#"loginStatus"];
Later you'll be able to retrieve that value as plain BOOL using -boolForKey: function in NSUserDefaults and based on that you can check if a user is already logged in.
Also you can maintain in Local database, coredata etc based on your requirement.
UPDATE
If you want to maintain the session, You can ask the server team to provide you an accesstoken on the login API response & save that as a String in NSUserDefaults and pass that string in your service calls.
If login is success, have below.
[[NSUserDefaults standardDefaults] setValue:#"yes" forKey:#"isLoggedIn"];
[[NSUserDefaults standardDefaults] synchronize];
For checking use below.
if ([[[NSUserDefaults standardDefaults] valueForKey:#"isLoggedIn"] isEqualToString:#"yes") {
NSLog(#"You are logged in");
} else {
NSLog(#"You are not logged in");
}
I am not sure about your server implementation. Usually, when logged in, the client(mobile app) will receive a token. This token should be included in the requests made afterward to show to the server that this user is logged in.
The http header is a good place to start to check whether some token is set when the login api is returned from the server. If yes, you may need to save that token:
[[NSUserDefaults standardDefaults] setValue:token forKey:#"loginToken"];
[[NSUserDefaults standardDefaults] synchronize];
Then, if the app is killed, upon launch:
NSString *token = [[NSUserDefaults standardDefaults] valueForKey:#"loginToken"];
//set the token to http header
I need to add one piece of functionality which relates to local storage when the app loads the first time after its downloaded from the app store. I have developed my app using only using jquerymobile and cordova
What I need is some code to achieve the following
Once the app is downloaded onto the iphone / ipad and its opened the app needs to check for the presence of a local storage value called AppID
If appID value does not exist in local storage the app needs to generate a random AppID that is in the following format xxx-xxx-xxx-xxx-xxx-xxx where the x values can be numbers or characters
The randomly generated AppId then needs to be placed in local storage so that it remains in place even after the iphone is rebooted and is only deleted if the app is deleted from the phone.
On the home page of the App I then need to have the AppID value retrieved from local storage displayed
If anyone can directly me to sample code that achieves the above or has already written code that achieves the above i would be very greatful
Use the following code in delegate class method didFinishLaunchingWithOptions
if ([[NSUserDefaults standardUserDefaults] intForKey:#"appID"]==0)
{
//first time launch
//generate an appID and save
[[NSUserDefaults standardUserDefaults] setInteger:app_id forKey:#"appID"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
//has launched before or app_id has been saved before, retrieve app_id
app_id=[[NSUserDefaults standardUserDefaults] intForKey:#"appID"]
}
As far as I know localStorage in not persistent with ios. ios can delete localStorage whenever it needs memory. You can just use a database like webSQL to save your app_id and check at the beginning of the app that it is set or not and if set,what it's value.
We are developing an iPhone application. The app is available in the app store. We are using NSUserDefaults to store our usertoken value. But some users reports that the usertoken is became null when the app idle (in background) for long time. But normally the value is getting.
The following is the code for storing usertoken in the NSUserDefaults. We are setting the value to the userToken from the login page and signup pages.
[[NSUserDefaults standardUserDefaults] setObject:userToken forKey:USER_TOEKN];
I have not called synchronize after setting value to NSUserDefaults. Could you please help
You need to call [[NSUserDefaults standardUserDefaults] synchronize]; if your app is going to be backgrounded - my guess is the app idles before the defaults automatically synchronizes. From the documentation:
Because this method is automatically invoked at periodic intervals, use this method only if you cannot wait for the automatic synchronization (for example, if your application is about to exit) or if you want to update the user defaults to what is on disk even though you have not made any changes.
As for where to do this, take a look at applicationWillResignActive: and applicationDidEnterBackground: in your Application Delegate.
Try something like this:
NSUserDefaults *udf = [NSUserDefaults standardUserDefaults];
[udf setObject:userToken forKey:USER_TOEKN];
[udf synchronize];
It will store your value permanently.
I am writing a first iOS app.. It's just getting user input and sending it to customized API.
However, when the user is in some black spot (no signal), I want the app to save the data into local and automatically send it when network becomes available..
What is the best and simple way to achieve this?
Use Reachability to detect whether the user has an Internet connection or not. If they do, send the data normally. If they don't have an Internet connection, then save the data into the Documents Directory or using NSUserDefaults.
[[NSUserDefaults standardUserDefaults] setObject:object forKey:#"Data1"];
NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:#"Data1"];