问题
I'm writing a research application that takes advantage of a specific sensor that broadcasts data over UDP. There are various commercial apps that use this sensor and we are hoping to be able to run both our application and an existing application side by side.
In the past (iOS 8 and below) we would run our application in the background to record data and a different application in the foreground. Unfortunately it appears only a single application was able to bind to the incoming UDP data (which makes sense), however with the coming 'side-by-side' application capabilities I was wondering if there was any solution to share data between the applications.
The only thing I could think of was to somehow have our app capture the data and re-broadcast it out to the other application but I'm not aware of whether that is possible in iOS, and even if it was how you would determine "who" has a lock on the UDP stream.
Apples documentation at: https://developer.apple.com/library/prerelease/ios/documentation/WindowsViews/Conceptual/AdoptingMultitaskingOniPad/index.html#//apple_ref/doc/uid/TP40015145 doesn't seem to offer much information.
回答1:
I am not certain of whether or not this will apply to your use-case but you may want to use CloudKit to send data to a custom app container. In the app capabilities section of your second app you can access the shared container.
From iCloud Design Guide:
When you enable the iCloud Documents or CloudKit capability, Xcode configures your app to access the iCloud container whose name is based on the app’s bundle ID. Most apps should only need access to the default container. If your apps share data among each other, enable the “Specify custom container identifiers” option and add one or more container IDs that you use to share data.
Sourced From Apple ~ see original for more details
Share Containers Between Apps
Optionally, configure your app to use multiple containers or share a container with other apps. For example, you might use one app internally to create record types and records programmatically to return a database to a known state. This app needs to share the same container as the end-user app you are developing and testing. To do this, you enable the first app to use the default container of the second app or create a custom container that both apps share. iOS and Mac apps can also be configured to share the same containers.
Add Containers to an App
Select an existing container ID used by another app or create a new one.
To add a container to an app
In the Capabilities pane under the iCloud settings, select “Specify custom containers.”
When you previously selected the CloudKit service, Xcode created a default container ID for your app that matches the bundle ID. A checkmark appears next to the default container ID.
If necessary, click the Refresh button below the Containers table to download containers from Member Center that are used by other apps. In the row of the container ID you want to add, select the checkbox. Xcode updates the list of container IDs in the entitlements file.
The screenshot below shows the Curator and Gallery app sharing the Gallery app’s default container.
Create Custom Containers
Alternatively, create a custom container shared by multiple apps.
Important: Only team admins can create containers. If you are an individual, you are the team agent (with admin privileges) for your one person team.
To create a custom container
If "Use default container” is selected, select “Specify custom containers.”
Click the Add button (+) at the bottom of the table. In the dialog that appears, enter an identifier for the container you want to add.
Warning: You can’t delete a container ID, so choose the container ID carefully.
A container ID begins with iCloud. followed by a string in reverse DNS notation, as in the iCloud.com.example.gkumar1.SharedGallery container ID.
Click OK.
Xcode adds the new container ID to the Xcode project entitlements file and to Member Center.
If you want to share the new container ID with another app, add the container to the app, as described in Add Containers to an App.
Verify Your Steps
You can view all the container IDs for your team in the iCloud settings or Member Center. In Member Center, you can also add containers and edit the name of containers.
To view container IDs in Member Center
In Member Center, select Certificates, Identifiers & Profiles. Under Identifiers, select iCloud Containers.
来源:https://stackoverflow.com/questions/32463375/sharing-udp-data-across-apps-background-foreground-or-split-screen-multitasking