Xamarin.iOS - NewBox
This sample shows you how to:
- Use
UIDocumentMenuViewController
andUIDocumentMenuViewController
. - Create Document Provider extensions: DocumentPickerViewController Extension and FileProvider Extension.
- Work with built-in iCloud storage provider.
We strongly recommend you to read the following guides before you start:
When you run the app you will see two columns. First column shows Document Picker directly and the second shows you Document Picker Menu. Document Picker Menu allows you to select Document Picker and add custom options.
Document Provider extension consists in two parts: Document picker extension and File provider extension. These extensions are presented with the following projects:
NBox
– Document picker extension.NBoxFileProvider
– File provider extension.
Setup
You need to setup an Application IDs with App Groups and iCloud. Then you need to generate a provisioning profile linked to the newly created AppID. To setup AppIDs, App Groups, Provisioning profiles please look at this introduction. Also have a look at next section, here you will find step by step instructions for Xamarin Studio (the same should work in Visual Studio)
iOS 8.0 provides a single and built-in iCloud storage provider. The goal of this sample is to add an other storage provider.
To start using the Document Picker and Open/Import from the iCloud storage Provider, you need to create some documents in iCloud iOS 8. The easiest way to do so is to use one of the following apps:
- Pages
- Numbers
- Keynote
You can donwload these apps from the iOS Dev Center. Choose iOS 8 tab and download the app's *.dmg
file.
Also to use Document Picker's Export/Move feature you need to be able to export or move documents to an other app which is compatible with iCloud Drive feature. In order to use that, you need to update your mac to Yosemite. Then you will be able to export documents to Preview or TextEdit apps.
Setup. Xamarin Studio
- Open the solution
- Inside the NBox project open the
Entitlements.plist
file and scroll down toApp Groups
section and changegroup.com.xamarin.NewBox,security
togroup.com.yourcompanyname.NewBox,security
replacingyourcompanyname
with your company name (to make id unique) - Open the
Info.plist
and also change the Application Name and Bundle Identifier tocom.yourcompanyname.NewBox.NBox
- In the NBoxFileProvider project open the
Entitlements.plist
file and scroll down toApp Groups
section and changegroup.com.xamarin.NewBox,security
togroup.com.yourcompanyname.NewBox,security
replacingyourcompanyname
with your company name (to make id unique) - Open the
Info.plist
and change the Bundle Identifier tocom.yourcompanyname.NewBox.NBoxFileProvider
- Click on the
Source
tab and scroll down to and expand theNSExtension
key. Change the value for:NSExtensionFileProviderDocumentGroup
fromgroup.com.xamarin.NewBox.security
togroup.com.yourcompanyname.NewBox.security
- In the NewBox project open the
Entitlements.plist
file. In theiCloud
section, change:iCloud.com.xamarin.NewBox
toiCloud.com.yourcompanyname.NewBox
- Click on the
Source
tab and change the value for thecom.apple.developer.icloud-container-identifiers
key from:iCloud.com.xamarin.NewBox
toiCloud.com.yourcompanyname.NewBox
- Open the
Info.plist
file and change the Bundle Identifier from:com.xamarin.NewBox
tocom.yourcompanyname.NewBox
- Go to Apple's Developer portal
- Make sure you have a valid Developer certificate and that it has been installed on your Mac.
- In the
Identifiers
section selectiCloud Containers
and click the+
button to add a new iCloud Container App ID. Name it whatever you like (but memorable) and make the ID:iCloud.com.yourcompanyname.NewBox
- In the
Identifiers
section selectApp Groups
and click the+
button to add a new App Group ID. Name it whatever you like (but memorable) and make the ID:group.com.yourcompanyname.NewBox.security
You will need to do the following three times, once for each project in the NewBox solution.
- In the
Identifiers
section select App IDs and click the+
button to add a new App ID. Set App ID Description to whatever you like (but memorable). Use anExplicit App ID
for App ID Suffix and use the bundle identifier for the project. So you need three of these App IDs, one for each bundle identifier:com.yourcompanyname.NewBox
com.yourcompanyname.NewBox.NBoxFileProvider
com.yourcompanyname.NewBox.NBox
- In the
Enable Services
section For all three App Ids, enableiCloud and App Groups
, and use theInclude CloudKit support
option for iCloud. - Click
Continue
. You may note that App Groups and/or iCloud show up as configurable. We will configure that in a bit. - Click
Submit
- Once you have the App Ids for all three projects, then you need to configure the
App Groups
andiCloud
for the App Ids. - Select each of the three app ids you just created and choose
Edit
. - Click the
Edit
button next toApp Groups
and select the App Group ID you created step 13 above. ClickContinue
. - Click the
Edit
button next toiCloud
and select the iCloud Container you created step 12 above. ClickContinue
. - When done, click
Done
. - Now you need to create three provisioning profiles, one for each App ID created in steps above. Use type iOS App Development.
- After selecting the App ID for the profile, click
Continue
and select the Developer certificate(s) to use with that profile. - Click
Continue
and select the Devices that the profile will be valid on. (you may need to set up some devices in the Devices section if you have not done that already). - Click
Continue
and name the profile (something memorable) and clickGenerate
. - Once generated, click the
Download
button to download it to your Mac. Double click the downloaded Provisioning profile to install it in XCode. - Once you have all of those profiles created, make sure to go into the Project Options page for each project and set your
Signing Identity and Provisioning Profile
to the certificates ad profiles created above. (Project Options->Build->iOS Bundle Signing page) - Try running the NewBox sample!
Open/Import documents from iCloud document provider with Document Picker
- Create some documents in iCloud container. For this step you need Pages, Numbers or Keynote.
- Run the NewBox app.
- Choose
Open
orImport
. - Choose a file and tap on it.
UIDocumentViewController
will be dismissed. - Look at the device's console output to see the results (file content).
Export/Move documents to iCloud document provider with Document Picker
- For this step you need mac with Yosemite.
- Run the NewBox app.
- Choose
Export
orMove
. - Select a destination (e.g. within
Preview
orTextEdit
folder) and tap onExport(Move) to this location
- Go to
Finder
on your Mac and chooseiCloud Drive
. Choose a folder (e.g.Preview
orTextEdit
) - You will find your file.
Open/Import documents from NBox file provider extension
- Run the NewBox app.
- Choose
Open/Import
. - Enable your extension. Tap on
Locations
thenMore ...
. Enable extension. TapDone
. - Choose
Open
/Import
again. Tap on "Locations" and choose your extension. - Tap on
Untitled.txt
button. At this point file provider will provide a file for you. - Look at the console output.
Export/Move document to NBox file provider extension
- Run the NewBox app.
- Choose Export/Move.
- Enable your extension. Tap on
Locations
thenMore ...
. Enable extension. TapDone
. - Choose
Export/Move
again. Tap onLocations
choose your extension. - Tap on
Export/Move to this location
button. - Go to NBox user interface again and you will see the imported file.
Note
Don't use NSFileCoordinator
inside your app extension. Apple provide an explanation
Build Requirements
Building this sample requires Xcode 6.0 and iOS 8.0 SDK.
Target
This sample is runnable on iPhone/iPad.
License
Xamarin port changes are released under the MIT license