dotnet / docs-maui

This repository contains documentation for .NET Multi-platform App UI (MAUI).
https://docs.microsoft.com/dotnet/maui
Creative Commons Attribution 4.0 International
221 stars 190 forks source link

iOS service extensions #1434

Open davidbritch opened 1 year ago

davidbritch commented 1 year ago

Add content on how to add an iOS service extension to a MAUI project. This is supported, but there's no project template for it. Instead, it'll require re-using the project file created by the Xamarin.iOS template and porting it to MAUI.

https://github.com/dotnet/maui/issues/8299 https://github.com/dotnet/maui/discussions/3289

https://learn.microsoft.com/en-us/xamarin/ios/platform/extensions https://learn.microsoft.com/en-us/xamarin/ios/platform/extensions-with-xamarinforms

Update April 2023: While it's possible to get this working, iOS extensions have so many rough edges in .NET 6/7 that I'll hold off doc'ing this until some work's been performed in this area.

This item will add the templates: https://github.com/xamarin/xamarin-macios/issues/16127

vikher commented 7 months ago

Is there any guidance available on creating an IPA build locally using the dotnet publish command? Specifically, considering that the iOS extension might require its own provisioning profile, how can the command address this limitation as it seems to allow only one provisioning profile with parameters: dotnet publish -f $(iOSVersion) -c $(BuildConfiguration) /p:ArchiveOnBuild=true /p:RuntimeIdentifier=ios-arm64 /p:EnableAssemblyILStripping=false /p:CodesignKey=$(CodesignKey) /p:CodesignProvision=$(CodesignProvision)

skuzminov-softheme commented 5 months ago

@vikher Try to set build properties in the csproj file and let msbuild resolve it on the pipeline automatically:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net8.0-ios</TargetFrameworks>
    <UseMaui>true</UseMaui>
    <OutputType>Library</OutputType>
    <Nullable>disable</Nullable>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <ImplicitUsings>enable</ImplicitUsings>
    <PlatformTarget>ARM64</PlatformTarget>
    <MtouchDevice>iPhone</MtouchDevice>
    <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
    <ApplicationVersion>1</ApplicationVersion>
    <CodesignProvision>Automatic</CodesignProvision>
    <CodesignKey>iPhone Distribution</CodesignKey>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
  </PropertyGroup>

  <PropertyGroup>
    <IsAppExtension>True</IsAppExtension>
    <IsWatchExtension>False</IsWatchExtension>
  </PropertyGroup>
</Project>

and in yaml:

    - task: CmdLine@2
      displayName: 'Build iOS App'
      inputs:
        script: >
          dotnet publish {ProjectName}.csproj -f "net8.0-ios" -c Release -v n
          /p:ArchiveOnBuild=true 

Of course, the app and extension profiles should be installed before archiving. If you get ditto.exe error - try to build extension app before main project.