2017-12-08 4 views
0

각 클라이언트마다 다른 스타일의 앱을 사용할 수 있도록 프로젝트를 설정 했으므로 디자인을 스트리밍하려고합니다. 현재는 PCL이 있고 각 클라이언트에 Android 및 iOS 프로젝트가 있으므로 설정됩니다. 즉, 앱 사이드 코드에서 무엇인가를 변경하면 각 프로젝트에서 수동으로 변경해야합니다.Xamarin 공유 Android 및 iOS 앱이 여러 개인 기본 Android 및 iOS 프로젝트

저는 개인용 컬러 스타일링, 이미지 및 번들 식별자를 가진 다른 프로젝트 각각이 상속 할 수있는 플랫폼 특정 인터페이스 코드가있는 기본 Android 및 iOS 프로젝트가 있으므로 PCL과 기본 Android 및 iOS 프로젝트를 갖기 위해 변경하려고 시도해 왔습니다.

  • PCL Poject (공유 코드, 양식 등)
  • Android.Shared (안드로이드 애플리케이션/플랫폼 특정 코드를 공유 자원/지역화에)
  • Android.Client1Theme (사용자 정의 자원 (로고, 색상, 등) 클라이언트 1의 경우)
  • Android.Client2Theme (사용자 정의 자원 클라이언트 2에 대한 (로고, 색상 등)) 안드로이드 애플 리케이션을위한

  • iOS.Shared (공유 리소스/지역화에/플랫폼 특정 코드)

  • iOS.Client1Theme (클라이언트 2에 대한 사용자 정의 자원 (로고, 색상 등)) (클라이언트 1에 대한 사용자 정의 자원 (로고, 색상 등))
  • iOS.Client2Theme는

나는이 입수했습니다 새로운 안드로이드 프로젝트를 만들고 공유 된 안드로이드 프로젝트와 PCL에 대한 참조를 추가함으로써 단순히 안드로이드를 위해 일하십시오.

동일한 방식으로 iOS에서 작동하는 데 문제가 있습니다. 그것은 가까운, iOS 애플 리케이션은 올바른 스타일로 새로운 애플 리케이션으로 컴파일하지만 인터페이스 메소드에 액세스하려고 할 때마다 DependencyService가 충돌합니다. 다음은

exception thrown on iOS interface access

DependencyService.Get<ISystemFunctions>().ToggleTorch();

그러나 내가이 문제라고 생각하지 않습니다 오히려 DependencyService이 그것을 찾을 수 없습니다, 내 공유 프로젝트 내 인터페이스의 코드입니다.

[assembly: Dependency(typeof(SystemFunctions_iOS))] 
namespace SharedApp.iOS.iOS_Interfaces 
{ 
    public class SystemFunctions_iOS : ISystemFunctions 
    {   
     public SystemFunctions_iOS() 
     { } 

     public void ToggleTorch() 
     { 
      var device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video); 
      if (device == null) 
       return; 

      device.LockForConfiguration(out NSError error); 
      if (error != null) 
      { 
       device.UnlockForConfiguration(); 
       return; 
      } 
      else 
      { 
       device.TorchMode = device.TorchMode == AVCaptureTorchMode.On ? AVCaptureTorchMode.Off : AVCaptureTorchMode.On; 
       device.UnlockForConfiguration(); 
      } 
     } 
    } 
} 

내가 도와 줄 수있는 다른 것이 있다면 알려주십시오.

+0

'DependencyService.Get ()'메소드가 Android 프로젝트에서 작동 했습니까? –

+0

그래, iOS에서 잘 작동합니다. 내가 아래에 게시 오전 내 문제에 대한 해결책을 찾았 – LPQ

+0

* 안드로이드에 잘 작동합니다. – LPQ

답변

0

추가 라인을 선 [Register("AppDelegate")]

//[Register("AppDelegate")] NEEDED TO REMOVE THIS 
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 
{   
    public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
    { 
     global::Xamarin.Forms.Forms.Init(); 
     LoadApplication(new App());    

     return base.FinishedLaunching(app, options); 
    } 
} 

iOS.ClientThemeX에 대한 AppDelegate에 제거를 iOS.Shared에 대한 AppDelegate에에서 내 문제

에 대한 해결책을 찾을 수 var systemFunctions_iOS = new iOS.Shared.iOS_Interfaces.SystemFunctions_iOS();

[Register("AppDelegate")] 
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 
{ 
    public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
    { 
     global::Xamarin.Forms.Forms.Init(); 
     LoadApplication(new App()); 

     // DO NOT REMOVE THIS. It breaks without it. Don't know why 
     // but a similar row will need to be added for each interface added to the project 
     var systemFunctions_iOS = new SharedApp.iOS.iOS_Interfaces.SystemFunctions_iOS(); 

     return base.FinishedLaunching(app, options); 
    } 
} 

공유 프로젝트에서 AppDelegate 레지스터를 제거하면 nse,하지만 왜 작동하도록 인터페이스가있는 새 객체를 선언해야하는지 잘 모르겠습니다. 이 인터페이스 생성자는 질문과 마찬가지로 비어 있습니다.

누구든지이 점에 대해 어떤 생각을 밝힐 수 있다면이 점에 대해 감사 할 것입니다. 그렇지 않으면 훨씬 간단한 방법으로 조언을 얻을 수 있습니다.