How to use another app's settings - iphone

What code could I use in an iPhone app to get and set the settings of another app I wrote? (preferably using NSUserDefaults)

You're not going to be able to pull this off with NSUserDefaults.
The Keychain, while somewhat cumbersome in its C-ness and much more limited than the NSUserDefaults API, might allow you to accomplish this. If you can serialize whatever you need to share between your apps into a few strings, it might be worth trying.
From iPhone OS 3.x Release Notes:
It is now possible for you to share Keychain items among multiple applications you create. Sharing items makes it easier for applications in the same suite to interoperate more smoothly. For example, you could use this feature to share user passwords or other elements that might otherwise require you to prompt the user from each application separately.
Sharing Keychain items involves setting up the proper entitlements in your application binaries. Using Xcode, you must create an Entitlements property list file that includes the supported entitlements for your application. The process for creating this file is described in iPhone Development Guide. For information about the entitlements you can configure, see the description for the SecItemAdd function in Keychain Services Reference.
Accessing shared items at runtime involves using the Keychain Services programming interface with the access groups you set up during development. For information about how to access the Keychain, see Keychain Services Programming Guide.
Here's Buzz Anderson's Simple iPhone Keychain Code. You could use it to store key/value pairs as strings in the keychain. It's not much, but perhaps better than nothing. See Apple's Keychain Programming Guide for more.

You simply cannot do that. Each application is installed into its own folder and is given its own, unique user id. The file containing these settings is in the other application's folder and its permissions are set to that of the other application. The only way to access the data is to use the same application identifier as the other application, in which case installing your application would overwrite the old application.
EDIT:
This solution was given when the question was asking to do this using NSUserDefaults, specifically. For the updated question, the keychain approach or the server approach provided are both reasonable.

You can have one app send the data to your server, then the other app can get the data from your server.
You can't do this using NSUserDefaults but it can be done.

You could use a shared clipboard. It wouldn't be secure, but both apps could read and write from the same clipboard. You just need to create an application specific UIPasteboard. Check out the UIPasteboard class reference on Apple's developer site for more info.
--Mike

You should definitely have a look at UIPasteboard, as suggested – you can create a new pasteboard for use by the applications you are creating (though nothing will stop other apps using them, but people are faily unlikely to). A UIPasteboard is persistent through a power cycle / reboot – it will exist until the creating application is deleted.
You could also have a look at the SwapKit libary (which looks very cool):
http://infinite-labs.net/swapkit/

Related

How to share data between applications in iphone

I have created one app. It is an update of another application. I have to use the data of first application when launching the second application. How can I accomplish this? My database files are with the same names.
iPhone apps are sandboxed. You can't access any other app's documents folder. Not even your own ones. You can share keychains between your apps or you can open other apps with an argument or a document. That's about it.
In addition to the aforementioned keychain sharing:
How to share keychain data between iOS applications
, if you involved a server, you could use the server as a mediator to exchange information between the two sandboxes.
It is also possible to have one application send another file to another application (although this results in a copy from one sandbox to the other) via registered mime types:
How do I associate file types with an iPhone application?
You can also share information via URL handlers.
http://mobileorchard.com/apple-approved-iphone-inter-process-communication/

Can I use Keychain Across iPhone Apps, from an SDK?

I am writing an SDK which will ship as a static library. Can I access the keychain to store data so that I can retrieve it in another app which also has my library? Seems like Apple would frown upon this, since I did not sign the apps, but am merely a passenger in the app's code.
Was looking at using "SFHFKeychainUtils" to help implement this. Any thoughts?
AFAIK, the keychain can only be shared across apps with the same Bundle Seed ID (which would be controlled at the signing level, as you say). As such, the only apps that would be able to share keychain access would be apps from any single developer. Cross-developer sharing is a no-go.
Check out more iOS security info here in Apple's docs.

Can keychains in IOS be compared to DPAPI in Windows?

On iOS, I am looking for an API equivalent to the encrypt/decrpyt DPAPI functions available on Windows (with CRYPTPROTECT_LOCAL_MACHINE flag not set).
The objective is to persist some application data locally and making its access restricted to the application itself only.
I've read about the keychain functionality but it seems that the dictionary has user-level access (unlocked during smartphone logon). I would like the application to be the only one who has access to that information, like, typically, having its own keychain.
Any advice on this?
An app cannot access another app's keychain entries in iOS. In principle, it's as if each app has its own keychain.
In iOS, an application can always access its own keychain items, but
not items created by any other application.
http://developer.apple.com/library/mac/#documentation/Security/Conceptual/keychainServConcepts/02concepts/concepts.html
However, see this post for other keychain security concerns.

Can I hide or make my iphone Application unsearchable on the App Store?

I want my application to be unsearchable from the App Store. I would like that only those users who sign in to my web site and then click the link of my iPhone application on app store, can install and use my application.
Is there any way to do that?
To hide your application you have to remove all the App Store countries in iTunes Connect:
Go in Manage your Applications > [Your Application Name] > Rights and Pricing
Click on "Deselect All" App Stores and "Save". The Application will change state to "Developer Removed".
To get it back on the App Store, choose the countries where you want it publish.
PS: it might take more than some hours for changes to be reflected on the App Stores.
Your application will be found when they search for the name of the app or your name. There's no special option in iTunes Connect to hide your app.
While your application will be found when searched for, as long as it's not installed in large numbers, it won't show up in the top 50 lists. Which kind of is the same.
Tip: don't specify any keywords when registering your app, as these will improve the "searchability".
Edit: you might want to implement some kind of authentication in your app, so users who do have installed your app need to register first, before they can actually use it. Relying on your app not being found, isn't very "clean".
I think, without meaningful keywords your app should vanish amongst the 99.999 other apps.
As an alternative you could let everyone (search and) download the app and disable it until the user signed in.
You can also use in-house-distribution with the enterprise program (see here).
Apple sells special developer licenses if you want to control the installation. They are meant for Enterprises to develop and deploy applications for only their use. Here's an article about it:
http://www.infoworld.com/t/platforms/new-iphone-enterprise-developer-program-299-musings-about-iphone-app-licensing-648
Since iTunes Connect has been redesigned a bit, go to My Apps > Select your app > Pricing and Availability > Availability (2nd section) > Select Remove from sale.
The best bet is to use obscure keywords on submission along with an obscure app name.
Not sure if this is going to work, but it may be worth a try:
You can set the release date of the application to the future. This removes the app from the catalog, which is a common way to remove an app temporarily (e.g. when it has problems) until an update appears.
However (this is possibly the catch) I don't know if the app will then be still available for sale via link or if the link will become unusable too.
if i were you i'd implement a "key generator", which will produce a serial that will be used to activate your application. this key generator would be free to access on your site, so whoever downloads your application through your site, would know what to do.
for those who access the application through itunes, i would also place a small text which basically says that you need to visit your site to generate a key. this way, you'd ensure that anyone who has access to your site has access to your app, and whoever finds your app will access your site.
this is i think hack proof by definition as well because noone would bother hacking it, would they? you basically give away your own serial generator for free, so it defeats the whole purpose of hacking. im assuming your concern is site traffic though.

How to programmatically determine if DRM was removed from iPhone application?

How can I determine if DRM was removed from iPhone application bundle (to protect it from piracy)?
I have an iPhone app which integrates with a third party web service. I use the technique described in this question to find pirates and then have the app "phone home" with the user's device ID and user ID for the web service (I haven't done anything with this information yet, but I was thinking about contacting them and asking them nicely to purchase my app).
In addition, once a user has used my app for a certain amount of usage, I limit functionality and direct the pirates to the App Store for full functionality.
To my knowledge, there's only one way to remove DRM: Crackulous.
So to find out what to look for in a cracked application, I would run Crackulous on your app and compare the app bundles. It should be fairly easy to determine what's been changed by looking at filesizes and running a diff on the files in the bundle.
Once you know what the changes are and to what file(s), just look for those changes in your application to determine if the application has been cracked.
If you find out exactly which files should be checked, please post your findings here so others can benefit from your research.
My previous Stack Overflow question may help you out: Reducing piracy of iPhone applications
Its probably worth pointing out that there are no casual "pirates". Casual users cannot download your app from the app store without buying it. All the DRM-removal schemes require to be run on a legitimately purchased copy.
As to looking at the bundle for changes, as I recall all you need to do is step through the link-loader commands and ensure that the code bundle is still tagged as encrypted. No need to compare it with anything. You'll need to read about Mach-O file format to do this, but thats not difficult, its all documented on developer.apple.com