Saturday, February 16, 2013

Monotouch and UTI handling.

Just making a demo app of Google Cloud Printing in Monotouch, and I wanted to be able to pass specific mime types to my app via Monotouch.  There isn't a recipe on the site for it, so I went about figuring out how to do it myself.

As you can see in your Monotouch Project Options, you need to navigate to "IPhone Applications", then go to the Advanced tab.  

Go to the "Document Types" list, and add on a Name.. then put in your type, which should resolve a text string listed by type here:  Apple UTI References

For PDF, you obviously put 'com.adobe.pdf'.

After entering that value, if you build your application, when you open a PDF in a documentview you should be able to see your application listed in the "Open In" action.

You still have some code to drop though, you need to be able to pass that file into your view controller. 
So, below is what you put in your appdelegate.cs to get access to the stream for the file that was passed in to your application.

public override bool HandleOpenURL (UIApplication application, NSUrl url)
    NSInputStream stream = NSInputStream.FromFile(url.Path); = stream;
    return true;

No comments:

Post a Comment