开发者

How to use another app's settings

开发者 https://www.devze.com 2022-12-14 05:39 出处:网络
What code could I use in an iPhone app t开发者_JAVA技巧o 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 NSUserDefa

What code could I use in an iPhone app t开发者_JAVA技巧o 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/

0

精彩评论

暂无评论...
验证码 换一张
取 消