iOS Declare Help!

I’m trying to setup the right declares so that I can call the iOS document picker:
(https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIDocumentPickerViewController_Class)

I’m doing it step by step and so far I have:

declare function initWithDocumentTypes Lib UIKitLib selector "initWithDocumentTypes:inMode:" (obj_id as ptr, allowedUTIs as ptr, mode as integer) as ptr dim obj as ptr = NSObject.Allocate(NSClassFromString("UIDocumentPickerViewController")) dim allowedUTIs as new NSArray(new NSString("public.text")) dim docPicker as ptr = initWithDocumentTypes(obj, allowedUTIs, 1)

(I’m using iOSKit for the helper functions and classes NSObject, NSClassFromString, etc.)

The problem is the app crashes when I call initWithDocumentTypes. I’ve tested it in the emulator and on a device. I’ve been trying to get this working for days and I can’t figure out what is wrong.

Can you see anything wrong with the declares? Thanks!

dim obj as ptr = NSClassFromString(“UIDocumentPickerViewController”)

you need the Pointer to the class to call init

Yes I’m already calling it in the code I posted:

dim obj as ptr = NSObject.Allocate(NSClassFromString(“UIDocumentPickerViewController”))

I also tried it without Allocate and it still crashes.

You are using NSArray incorrectly. The way you currently have it you are creating an array from an NSString object. Instead you want to put the NSString into an array. Use the NSArray.CreateWithObject method and pass the NSString into that. Then it should work.

Thanks. I changed it to:

dim allowedUTIs as NSArray = NSArray.CreateWithObject(new NSString(“public.text”))

But it still crashes when calling initWithDocumentTypes

Mode should be UInteger… as per the docs

Thanks I changed it but still crashes

Have you enabled iCloud document support?

Yes.

Also, if I call initWithDocumentTypes(nil, nil, 1) it doesn’t crash, but it returns nil of course. But I don’t think the parameters are crashing it, it is something with the declare I think… But I could be wrong.

I just spent the last 10 or so minutes putting together the class using DeclareMaker and the error that I get is

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?'

It seems like the entitlements aren’t being properly set since I have selected all of the different possible combinations of iCloud settings in the Advanced build tab and it still continues to fail. (I’m seeing the same thing with Push Notification stuff). Maybe the entitlements aren’t actually being applied correctly still?

Additional note is that you won’t be able to easily get the result (either the selected file or that the user cancelled) without encapsulating your code into a class because you have to set a delegate. I have done that if you want to view it, just check the develop branch of iOSKit.

Thanks! I will check out your code and I will try to get the entitlements properly set up and then I will let you guys know what happens…

I’m not sure its going to be possible. I just built iOSKit two different times and inspected the entitlements in the embedded profile and there was no change between builds even though I disabled all entitlements for the first build and enabled several for the second build. The entitlements for the app itself were properly updated however, although they still differ slightly from a test app from Xcode using the exact same set of entitlements… Looks like I’m going to have to file a feedback case.

To view entitlements, you need the following commands (replace TEST with your app name, and change your working directory to the build location):
app entitlements:

codesign -d --entitlements :- "TEST.app"

embedded entitlements:

security cms -D -i "TEST.app/embedded.mobileprovision"

OK thanks that really helps. Is there a way to manually set entitlements during the build process in a build script, before the app is signed?

Another interesting piece of information: the “embedded.mobileprovision” file responsible for the embedded entitlements is dated July 22 and not today like nearly everything else in the folder so it seems like Xojo caches the file somewhere. Does anyone (probably at Xojo) know where I could find this cached file to force Xojo to update the entitlements so this will work properly?

Hmmm embedded.mobileprovision file is dated today for my project’s build. But I did build ioskit and it was using a file with a date of yesterday for me. odd…

So there is no way of manually modifying the provision file? I hope the Xojo staff can help!

[quote=228595:@George Ashkar]Hmmm embedded.mobileprovision file is dated today for my project’s build. But I did build ioskit and it was using a file with a date of yesterday for me. odd…

So there is no way of manually modifying the provision file? I hope the Xojo staff can help![/quote]
There should be, but I don’t think that Xojo is respecting it right now. I think it might have something to do with when the project is first opened/created on your computer, but I haven’t been able to find the cached file to delete it and force Xojo to recreate it with the proper settings specified in the inspector.

Keep in mind the mobileprovision file comes from Apple. Make sure you’ve updated your entitlements to include the necessary iCloud stuff on Apple’s developer site- and that you’ve refreshed in Xcode so the mobileprovision file is up to date and has the iCloud entitlement that you want. We get the mobileprovision files from here: ~/Library/MobileDevice/Provisioning Profiles/

  1. I created a new app id at developer.apple.com and turned on the following options:
  • Include CloudKit support (requires Xcode 6)
  • I also created an iCloud container and associated it with the app id
  1. I also created a provisioning profile for the app id and associated it with an iPhone device so I can test on a real device also

  2. In the Xojo IDE I set the new app id and then enabled the iCloud entitlement:

  • Key Value Storage
  • iCloud Documents
  • CloudKit
  • Specified custom container id

And still get this crash log:

*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?’
abort() called
CoreSimulator 191.4 - Device: iPhone 5s - Runtime: iOS 9.1 (13B137) - DeviceType: iPhone 5s
terminating with uncaught exception of type NSException

Am I missing a step?

Whats in the app plist ?