2016-06-09 5 views
0

최신 Xamarin Alpha가 설치되어 있으며 UWP 및 DependencyService가 작동하지 않습니다. UWP 프로젝트에서 Xamarin.Forms DependencyService Get() 메서드가 PCL에서 Null을 반환합니다.

나는이 :

Forms.Init(e); 

// For release version, doc said debug will do this itself 
DependencyService.Register<SpecialInterface>(); 
IInterface1 iinterface1 = DependencyService.Get<IInterface1>(); 

이 인터페이스 포인터를 찾을 수 없습니다. PCL에서

나는이 : 그것은 UWP와 안드로이드 모두에서 Get<IInterface1>() 호출의 null 값을 반환 실패 PCL에 포함 된 뷰 모델에서
IInterface1 iinterface1 = DependencyService.Get<IInterface1>(); 

(버튼 클릭 후). 다음과 같이

using PrismUnityApp2.UWP; 
using SharedProject1; 
using Xamarin.Forms; 

[assembly: Dependency(typeof(SpecialInterface))] 

namespace PrismUnityApp2.UWP 
{ 
    public class SpecialInterface : IInterface1 
    { 
     public SpecialInterface() { } 

     public int TestMethod(int i) 
     { 
      return i; 
     } 
    } 
} 

마지막으로, 인터페이스가 공유 프로젝트에 정의되어 있습니다 :

namespace SharedProject1 
{ 
    internal interface IInterface1 
    { 
     int TestMethod(int i); 
    } 
} 

내가 샘플 "UsingDependencyService"에서 작업이 여기에

는 UWP 프로젝트에 포함 된 구현 Android의 경우 HyperV가 꺼져있어 WinPhone이 실패합니다.

무엇이 누락 되었습니까?

도움 주셔서 감사합니다.

사용하여 다음 패키지/버전 :

  • Prism.Unity.Forms 6.2.0.pre4
  • Prism.Forms 6.1.0.pre4
  • Xamarin.Forms 2.2.0.45
  • 유니티 4.0.1
  • 윈도우 10 UWP

    public void OnNavigatedTo(NavigationParameters parameters) 
    { 
        if (parameters.ContainsKey("title")) 
         Title = (string) parameters["title"] + " and Prism"; 
    
        IInterface1 iinterface1 = DependencyService.Get<IInterface1>(); 
        if (iinterface1 != null) 
        { 
         int value = iinterface1.TestMethod(1); 
         Title += " ::: " + value; 
        } 
    } 
    
+0

인터페이스를 공개로 설정해보십시오. –

+0

쉽게 해결할 수 있었지만 내부를 공개로 바꿨으나 여전히 실패합니다. 나는 오늘 그것을 다시 보게 될 것이므로 뭔가 찾을 수 있습니다. –

+0

등록 메소드 호출이 필요하지 않아야 속성이 충분합니다. DependencyService.Get 및 클릭 처리로 코드를 게시 할 수 있습니까? –

답변

1

DependencyService.Get<IInterface1>() 호출은 실제로 여러 번 정의되는 IInterface1의 다른 버전을 찾고 있기 때문에 PCL에서 null을 반환합니다.

IInterface1은 PCL 프로젝트와 UWP & Android 프로젝트에서 모두 참조하는 공유 프로젝트에 있기 때문에 기본적으로 동일한 이름과 서명을 사용하여 PCL과 앱 프로젝트에서 별도로 인터페이스를 만드는 것과 같습니다. 하지만 부모 어셈블리는 다릅니다. 기존 PCL 또는 기존 PCL 및 앱 프로젝트 모두에 의해 참조되는 별도의 PCL로 IInterface1를 이동한다면

, DependencyService 예상대로, 플랫폼 고유의 구현, SpecialInterface을 찾을 수 있습니다.

0

자 마린, iOS에서 널 (null) 결과를 참조 누구 경우 : ImagePickerService

DependencyService.도망(); 내가 포함 놓친 무엇을했다

, AppDelegate에에

Xamarin.Forms.DependencyService.Register<Xamarin.Forms.ImagePicker.IImagePickerService, Xamarin.Forms.ImagePicker.iOS.ImagePickerService>(); 

, FinishedLaunching 방법.

참조 : https://github.com/matheusneder/Xamarin.Forms.ImagePicker

관련 문제