问题
Scenario:
- I "control" two different apps, App A and App B, both which the user has installed
- App A is running
- App A needs to obtain a string that was set by App B when App B last ran.
- After obtaining the string, App A will still be running
- User should not receive any feedback this communication is happening. E.g. no "switching animations" between A or B, no pop-ups, etc.
Constraints:
- Apps are released under different vendors
- Apps are already in the app store; updated versions will have this communication ability.
- It is acceptable for the data stored in App B to be accessible to other apps on the device.
- It is not acceptable for the data stored in App B to be visible to general third parties (e.g. if an external server is used, there needs to be some sort of secured scheme)
- The data read should be able to occur immediately upon App A being opened after install. For instance, I cannot require the user of App A to enter log in credentials for an external communication service.
- Must work on non-jailbroken devices.
This is seeming rather difficult to pull off in iOS7. Help is appreciated.
回答1:
Tricky work around. Not recommended, but it will get the job done if you can't afford servers.
On the first app create a contact in the user's contacts book. Give it a generic name like "000 - NameOfAppB Data - Don't Delete" (I start with "000" so it goes to the bottom of the users contact book so they never see it, I also add "don't delete" so if the user does somehow find it they don't delete it hahaha) (who looks at contact books anyways). In the contact info under notes add your NSData in string format.
Then when app A is opened search for that contact, read the data, then delete the contact.
Apple does allow you to create and delete users contacts without their permission. (At least in 2011 they did, this may have changed).
回答2:
This might serve your purpose
https://developer.apple.com/library/ios/documentation/Security/Reference/keychainservices/Reference/reference.html
I am not sure of its limitations though, i have seen implementations where credentials have been shared between apps.
来源:https://stackoverflow.com/questions/22215092/how-can-one-app-provide-data-to-another-without-swiching-apps