Xamarin Notification Service Extension issue

后端 未结 2 522
夕颜
夕颜 2021-02-07 03:57

I have an issue with Notification Service Extension. I have followed step by step documentation https://developer.xamarin.com/guides/ios/platform_features/introduction-to-ios10

相关标签:
2条回答
  • 2021-02-07 04:20

    If anyone else comes here, the code by original poster works for me and the bug mention is now marked as fixed. If I have one tip, do not try to do this on Windows. You will be in for a whole world of pain and will get nowhere (actually, it did work for me, once!). Also expect Visual Studio on Mac to crash, a lot, if you try to debug!

    0 讨论(0)
  • 2021-02-07 04:31

    You are doing everything correctly, this is an issue raised by a few other xamarin developers. From what I can tell, as soon as you run the NSURLSession to download something, even if it's super super small, you go above the memory limit allowed for this type of extension. This is most probably very specific to xamarin. Here is the link to the bugzilla. https://bugzilla.xamarin.com/show_bug.cgi?id=43985

    The work-around/hack I found is far from ideal. I rewrote this app extension in xcode in objective-c (you could use swift too I suppose). It is a fairly small (1 class) extension. Then built it in xcode using the same code signature certificate / provisioning profile and then found the .appex file in the xcode's output.

    From then, you can take the "cheap way", and swap this .appex file in your .ipa folder manually just before resigning and submitting the app. If that's good enough for you, you can stop here.

    Or you can automate this process, to to so, place the appex file in the csproj's extension and set the build-action as "content". Then in this csproj's file (you'll need to edit directly) you can add something like this. (In this case, the file is called Notifications.appex and is placed in a folder called NativeExtension)

    <Target Name="BeforeCodeSign">
        <ItemGroup>
            <NativeExtensionDirectory Include="NativeExtension\Debug\**\*.*" />
        </ItemGroup>
    
        <!-- cleanup the application extension built with Xamarin (too heavy in memory)-->
        <RemoveDir SessionId="$(BuildSessionId)"
                   Directories="bin\iPhone\Debug\Notifications.appex"/>
    
        <!-- copy the native one, built in obj-c -->
        <Copy
                SessionId="$(BuildSessionId)"
                SourceFiles="@(NativeExtensionDirectory)"
                DestinationFolder="bin\iPhone\Debug\Notifications.appex"
                SkipUnchangedFiles="true"
                OverwriteReadOnlyFiles="true"
                Retries="3"
                RetryDelayMilliseconds="300"/>
    </Target>
    

    This gives you the general idea, but obviously if you want to support ad-hoc distribution signature, iOS app-store distribution signature you will need to add a bit more code into this (and possibly add in the csproj a native appex file for each different signature), I would suggest putting such xml code in separate ".targets" file and use conditional calltargets in the csproj. Like this:

    <Target Name="BeforeCodeSign">
        <CallTarget Targets="ImportExtension_Debug" Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' " />
        <CallTarget Targets="ImportExtension" Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' " />
     </Target>
    
    0 讨论(0)
提交回复
热议问题