Is NSUserDefault secured to store app group data? - nsuserdefaults

I have two apps, (AppA and AppB). I want to save data in AppA and access it in AppB using App Group:
Code in App A:
- (IBAction)btnSetValuePressed:(id)sender {
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.com.tcompany.testName"];
[myDefaults setObject:#"foo" forKey:#"bar"];
[myDefaults synchronize];
}
Code in App B:
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.com.tcompany.testName"];
NSString *myString = [myDefaults objectForKey:#"bar"];
self.lblResult.text = myString;
Problem:
Is It secured enough?

It is secure in the sense that only the apps with access to that app group can see that data.
Each app has a sandbox and only that app may access its content. Let's call these apps, "app A" and "app B", there are therefore two sandboxes, sandboxA and sandboxB
When you define an app group you effectively create a third sandbox that is shared between your apps, let's call it sandboxC
Only those two apps can see that shared data, so in this expanded sense both apps as a pair have a secure private area for data.
App A can see sandboxA but not sandboxB
App B can see sandboxB but not sandboxA
Both app A and B can read and write to SandboxC
Note that both apps run in different processes so it could be possible for App A to be writing data to sandbox C at the same time that app B is reading from the same stored data item, for this reason care must be exercised to avoid possible conflicts.
If you use NSUserDefaults as the storage medium you are going to be safe because Apple ensure that NSUserDefaults behaves correctly in these concurrent circumstances.

Related

How to list All iPhone Apps By a SIngle developer in iPhone App?

In My Application I want show all my iPhone apps from itunes store in a tableview. If user clicks any one of cell it leads to take to appstore of that application.I know just statically by giving link of each application. As per my need i need to get new apps also after this installation.
You can use the search web service provided by Apple: http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html#searching
I couldn't find a way to search by artist ID for software, but you can still perform a generic query using the developer name.
For example, this would return apps by Gameloft:
http://itunes.apple.com/search?term=Gameloft&media=software&lang=en_US&country=us
Note that it's a query by name,so you can have false positives (apps where the name Gameloft appears but are not real Gameloft apps). You have to check the artistId property for each returned app (in this case, Gameloft's artistId is 282764297).
If you want to open the App Store to a specific app, use the trackId you got from the previous web service and then
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:
[NSString stringWithFormat:
#"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",
trackId]]];
Instead of doing your own table view, you can also use StoreKit to display the apps, and let the user purchase other apps right there.
Just replace 383916386 with the correct id for your developer account.
SKStoreProductViewController *viewCtrl = [[SKStoreProductViewController alloc] init];
[viewCtrl loadProductWithParameters:#{SKStoreProductParameterITunesItemIdentifier: #"383916386"} completionBlock:nil];
[self presentViewController:viewCtrl animated:YES completion:nil];

To save username & password using objective c

I am having login view & after login some list is shown...so i want to save username & password so that login view does not appear once if login made with correct ID,password directly it will show the list
As others have suggested, you can use NSUserDefaults.
If you are storing the password, then I would suggest you also add a level of security to this. You could use Secure NSUserDefaults (I've not used this personally, but seen a few people reporting it being useful). You can find that here
Or you can use the KeyChain API
If you do not care about encryption, you could save these very simply with
[[NSUserDefaults standardUserDefaults] setValue:#"username" forKey:#"username"];
[[NSUserDefaults standardUserDefaults] setValue:#"secret" forKey:#"password"];
and check those during program startup with
if (![[NSUserDefaults standardUserDefaults] valueForKey:#"username"]) {
// show the login screen
}
you may use NSUserDefaults
Apple Documentation about NSUserDefaults
You can save this in the NSUserDefaults like this :
NSUserDefaults *userDefaults = [NSUserDefaults standardDefaults];
[userDefaults setBool#"YES" forlkey#"userDidLogin"];
And you test like this :
NSUserDefaults *userDefaults = [NSUserDefaults standardDefaults];
if([userDefaults boolForKey:#"userDidLogin"])
{
.... // Go to the list View
}
This is just an indication, if you would like to put it to work , you should show your code how you implement the implémentation of login interface
NSUserDefaults is just a handy way designed for customize app's preferences. In normal situation, an app will stay in it's own sandbox and therefore other apps won't be able to access it.
However it is not the best choice to do so. It's not good practice. What you really need is keychain and see here for apple's sample code for it, it's much safer in terms of security.
there are multiple ways to save user name and password..
You can save in UserDefalt as above answer.
also you can save in plist.

Check if app has been purchased

I am a beginner; I am trying to solve this but am unable to do so.
I have created an app that displays a few options in a table. When the user taps the cell the details of selected option is shown on another page (details are stored in a plist file).
What I want to do is to set it up so that if the user has purchased the app then only the details should be visible, but if the user has not purchased it, the user should be prompted to do so.
I have created a product ID for iTunes Connect and also created a testing account to test the app.
My problem is with the code: how should i check if user has already made the purchase?
Using NSUserDefaults is the easiest solution.
After a successful purchase:
[[NSUserDefaults standardUserDefaults]
setObject:#"purchased"
forKey:#"myPaidItem"];
[[NSUserDefaults standardUserDefaults]
synchronize];
And when you need to check if the user has purchased the item:
NSString* isPurchased =
[[NSUserDefaults standardUserDefaults]
stringForKey:#"myPaidItem"];
if ([#"purchased"
compare:isPurchased]==NSOrderedSame) {
........ }
Hope that helps
you have to store this information in appContext as a bool if the transaction is OK , boo= true
and when he want to buy another time you hve to check the value of boo wich is stored in app Context

iPhone / iOS Facebook SDK - can you log in within the app, and keep the login credentials?

Is it possible to use the Facebook iOS SDK to authenticate within an app (not go to Safari), and also keep those authentication credentials for the next launch of the app?
When I try to use the demo app in the simulator, it always goes to safari to authenticate, which seems a bit crappy. And then, when I authenticate... if I completely kill the app it will ask to authenticate again (and then tell me I am already logged in)
Is there a way, to just present the user with just an email field and a password field and then keep that info.. within the app?
Take a look at this question and answer: Iphone facebook connect example calls safari. I don't want to use safari. Also, you'll want to store the authentication stuff in NSUserDefaults and check for them to make to prevent re-logins.
EDIT Some sample code:
To save login stuff:
[[NSUserDefaults standardUserDefaults] setObject:_facebook.accessToken forKey:#"AccessToken"];
[[NSUserDefaults standardUserDefaults] setObject:_facebook.expirationDate forKey:#"ExpirationDate"];
[[NSUserDefaults standardUserDefaults] synchronize];
To check for login stuff:
_facebook = [[[Facebook alloc] initWithAppId:#"[app_id]"] retain];
_facebook.accessToken = [[NSUserDefaults standardUserDefaults] stringForKey:#"AccessToken"];
_facebook.expirationDate = (NSDate *) [[NSUserDefaults standardUserDefaults] objectForKey:#"ExpirationDate"];
if (![_facebook isSessionValid]) {
[_facebook authorize:_permissions delegate:self];
}
else {
[_facebook requestWithGraphPath:#"me" andDelegate:self];
}
You can hack round it to stop it if this is what you really want, bearing in mind most other apps that migrate from the older Facebook connect api to graph will behave in the new way
In facebook.m find the following method
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
safariAuth:(BOOL)trySafariAuth
find the bottom of the didOpenOtherApp logic and comment out all above it so that it always opens inline and tuns this section of code thats contained in the !didOpenOtherApp braces
// If single sign-on failed, open an inline login dialog. This will require the user to
// enter his or her credentials.
if (!didOpenOtherApp) {
[_loginDialog release];
_loginDialog = [[FBLoginDialog alloc] initWithURL:loginDialogURL
loginParams:params
delegate:self];
[_loginDialog show];
}
However by doing this you are making it more likely that the user will have to input their credentials, which is surely worse than putting up with the fast app switching approach?
When you first auth, make sure you're asking for "offline_access" permission. That will make the token that OAuth returns to you NOT be invalidated at the end of the session, but instead stay valid literally until they come along and use the API to log your app OUT of Facebook.
Then, obviously, you need to save the token (I feel like NSUserDefaults is a fine place for it) and reuse it on later FB interactions.

iphone Settings application persist data

In my app I'm using an NSUserDefaults object to store the username, password and server URL in the built-in Settings app. If there is no data saved, the user is presented a login interface and upon succesful login the username and password are saved. Then in my app I have a view which displays this information, but the text is missing as if the data hasn't been saved to the Settings yet. Here's the code:
...
NSUserDefaults* appSettings = [NSUserDefaults standardUserDefaults];
[appSettings setObject:username forKey:USERNAME];
[appSettings setObject:password forKey:PASSWORD];
if ( [appSettings synchronize] ) {
// display an alert with a positive message
} else {
// display an alert with a negative message
}
So, after logging in the positive message is displayed, but when I fetch the data again there is nothing there, unless I restart the app.
What do I need to do to save the data immediatly, or at least before another view controller needs to read the settings?
The NSUserDefaults object stores its data in memory, and is a global object (to your application, anyway). Thus, anything you store in there should be immediately available to anything that tries to access it afterwards. You don't need to call synchronize here. If you're not getting your data, you should check the order of your calls to make sure they're being called when you think they are.