[AVFoundaation] Fix bug 44322 - AVAssetDownloadUrlSession.CreateSession throws a System.InvalidCastException: Specified cast is not valid.

https://bugzilla.xamarin.com/show_bug.cgi?id=44322

AVAssetDownloadUrlSession.CreateSession according to headers it
should return an AVAssetDownloadUrlSession but it is returning
an apple internal type NSURLBackgroundSession so with our
current bindings it throws an InvalidCastException, adding
ForcedTypeAttribute will create the managed type wihout
the actual typecheck. Added test verifing that the API
no longer throws.
This commit is contained in:
Alex Soto 2016-09-23 19:17:57 -05:00
Родитель bcbe813ab1
Коммит 7845caa577
2 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -10453,6 +10453,7 @@ namespace XamCore.AVFoundation {
[BaseType (typeof (NSUrlSession), Name = "AVAssetDownloadURLSession")]
interface AVAssetDownloadUrlSession {
[Static]
[ForcedType]
[Export ("sessionWithConfiguration:assetDownloadDelegate:delegateQueue:")]
AVAssetDownloadUrlSession CreateSession (NSUrlSessionConfiguration configuration, [NullAllowed] IAVAssetDownloadDelegate @delegate, [NullAllowed] NSOperationQueue delegateQueue);

Просмотреть файл

@ -11,6 +11,7 @@
#if !__WATCHOS__ && !__TVOS__
using System;
using ObjCRuntime;
#if XAMCORE_2_0
using Foundation;
@ -38,6 +39,20 @@ namespace monotouchtest {
Assert.Throws <NotSupportedException> (() => AVAssetDownloadUrlSession.FromWeakConfiguration (NSUrlSessionConfiguration.DefaultSessionConfiguration, new NSObject (), null), "FromWeakConfiguration should throw NotSupportedException");
}
[Test]
public void CreateSessionTest ()
{
if (!TestRuntime.CheckXcodeVersion (7, 0))
Assert.Ignore ("Ignoring AVAssetDownloadUrlSession tests: Requires iOS9+");
if (Runtime.Arch == Arch.DEVICE)
Assert.Ignore ("Ignoring CreateSessionTest tests: Requires com.apple.developer.media-asset-download entitlement");
using (var backgroundConfiguration = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration ("HLS-Identifier")) {
Assert.DoesNotThrow (() => AVAssetDownloadUrlSession.CreateSession (backgroundConfiguration, null, NSOperationQueue.MainQueue), "Should not throw InvalidCastException");
}
}
// FIXME: Disabling this test from now, will reenable once apple releases docs on what is ecpected to have this entitlement key
// Reason: Creating an AVAssetDownloadURLSession requires the com.apple.developer.media-asset-download entitlement
// [Test]