feature: open with extension

This commit is contained in:
Tsanie Lily 2020-05-09 20:10:33 +08:00
parent e6b5bea459
commit f42705d1d2
6 changed files with 207 additions and 0 deletions

View File

@ -0,0 +1,6 @@
<?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>
</dict>
</plist>

View File

@ -0,0 +1,36 @@
<?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>Pixiview.iOS.OpenExtension</string>
<key>CFBundleName</key>
<string>Pixiview.iOS.OpenExtension</string>
<key>CFBundleIdentifier</key>
<string>org.tsanie.Pixiview.OpenExtension</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>13.4</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>TRUEPREDICATE</string>
</dict>
<key>NSExtensionPrincipalClass</key>
<string>OpenExtensionHandler</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
</dict>
</plist>

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProjectGuid>{618D8350-495C-42D0-9DAC-87ADD36AC727}</ProjectGuid>
<ProjectTypeGuids>{EE2C853D-36AF-4FDB-B1AD-8E90477E2198};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>Pixiview.iOS.OpenExtension</RootNamespace>
<AssemblyName>Pixiview.iOS.OpenExtension</AssemblyName>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchFastDev>true</MtouchFastDev>
<IOSDebuggerPort>28687</IOSDebuggerPort>
<MtouchLink>None</MtouchLink>
<MtouchArch>x86_64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<DeviceSpecificBuild>false</DeviceSpecificBuild>
<MtouchVerbosity></MtouchVerbosity>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<DefineConstants></DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchFloat32>true</MtouchFloat32>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchArch>ARM64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<MtouchVerbosity></MtouchVerbosity>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<DefineConstants></DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchLink>None</MtouchLink>
<MtouchArch>x86_64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<MtouchVerbosity></MtouchVerbosity>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<DeviceSpecificBuild>true</DeviceSpecificBuild>
<MtouchDebug>true</MtouchDebug>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchFastDev>true</MtouchFastDev>
<MtouchFloat32>true</MtouchFloat32>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<IOSDebuggerPort>13559</IOSDebuggerPort>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchArch>ARM64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<MtouchVerbosity></MtouchVerbosity>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
<None Include="Entitlements.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="ShareViewController.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.AppExtension.CSharp.targets" />
</Project>

View File

@ -0,0 +1,46 @@
using Foundation;
using MobileCoreServices;
using UIKit;
namespace Pixiview.iOS.OpenExtension
{
[Register("OpenExtensionHandler")]
public class OpenExtensionHandler : NSExtensionRequestHandling
{
public override void BeginRequestWithExtensionContext(NSExtensionContext context)
{
bool urlFound = false;
foreach (var item in context.InputItems)
{
foreach (var provider in item.Attachments)
{
if (provider.HasItemConformingTo(UTType.URL))
{
provider.LoadItem(UTType.URL, null, (obj, error) =>
{
var url = obj as NSUrl;
if (url != null)
{
var uri = NSUrl.FromString($"pixiview://open{url.Path}");
System.Diagnostics.Debug.WriteLine($"open url: {uri}");
BeginInvokeOnMainThread(() => UIApplication.SharedApplication.OpenUrl(uri));
}
});
urlFound = true;
break;
}
}
if (urlFound)
{
break;
}
}
context.CompleteRequest(new NSExtensionItem[0], null);
}
}
}

View File

@ -149,6 +149,11 @@
<Project>{7F310047-BCBB-45F5-BD16-F246BA72AF73}</Project>
<Name>Pixiview</Name>
</ProjectReference>
<ProjectReference Include="..\Pixiview.iOS.OpenExtension\Pixiview.iOS.OpenExtension.csproj">
<IsAppExtension>true</IsAppExtension>
<Project>{618D8350-495C-42D0-9DAC-87ADD36AC727}</Project>
<Name>Pixiview.iOS.OpenExtension</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Renderers\" />

View File

@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pixiview", "Pixiview\Pixivi
EndProject
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "Pixiview.Android", "Pixiview.Android\Pixiview.Android.csproj", "{EEE719E5-36B4-4024-84F5-F71DF07B3308}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pixiview.iOS.OpenExtension", "Pixiview.iOS.OpenExtension\Pixiview.iOS.OpenExtension.csproj", "{618D8350-495C-42D0-9DAC-87ADD36AC727}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -53,5 +55,17 @@ Global
{EEE719E5-36B4-4024-84F5-F71DF07B3308}.Debug|iPhone.Build.0 = Debug|Any CPU
{EEE719E5-36B4-4024-84F5-F71DF07B3308}.Release|iPhone.ActiveCfg = Release|Any CPU
{EEE719E5-36B4-4024-84F5-F71DF07B3308}.Release|iPhone.Build.0 = Release|Any CPU
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Release|Any CPU.Build.0 = Release|iPhoneSimulator
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Debug|iPhone.ActiveCfg = Debug|iPhone
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Debug|iPhone.Build.0 = Debug|iPhone
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Release|iPhone.ActiveCfg = Release|iPhone
{618D8350-495C-42D0-9DAC-87ADD36AC727}.Release|iPhone.Build.0 = Release|iPhone
EndGlobalSection
EndGlobal