Skip to content

Instantly share code, notes, and snippets.

@wcoder
Last active February 10, 2020 14:49
Show Gist options
  • Save wcoder/d6eca8c37ef21f0d0255536570d117ce to your computer and use it in GitHub Desktop.
Save wcoder/d6eca8c37ef21f0d0255536570d117ce to your computer and use it in GitHub Desktop.
Simple Xamarin.iOS application for opening files with custom extension.
using System;
using System.IO;
using Foundation;
using UIKit;
namespace PocOpenFileiOS
{
[Register(nameof(AppDelegate))]
public class AppDelegate : UIApplicationDelegate
{
// ...
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
if (url != null && url.IsFileUrl)
{
// TODO: check file extension
var a = NSData.FromUrl(url);
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine(documents, "new_file.4321c");
if (a.Save(filename, true, out _))
{
//var data = File.ReadAllText(filename);
}
return true;
}
return false;
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>PocOpenFileiOS</string>
<key>CFBundleIdentifier</key>
<string>name.pakalo.evgeniy.PocOpenFileiOS11</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
<string>13.2</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIMainStoryboardFile~ipad</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string>
<key>CFBundleName</key>
<string>PocOpenFileiOS</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Client certificate</string>
<key>CFBundleTypeIconFiles</key>
<array>
<string>Icon-App-29x29@2x</string>
</array>
<key>LSItemContentTypes</key>
<array>
<string>name.pakalo.evgeniy.PocOpenFileiOS11.c1234</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeDescription</key>
<string>XDXF - XML Dictionary eXchange Format</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.text</string>
</array>
<key>UTTypeIdentifier</key>
<string>name.pakalo.evgeniy.PocOpenFileiOS11.c1234</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>c1234</string>
</array>
<key>public.mime-type</key>
<string>text/xml</string>
</dict>
</dict>
</array>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment