Как интегрировать два приложения в xamarin iOS? - PullRequest
0 голосов
/ 28 марта 2020

У меня есть два приложения. Один называется SincApp, который берет пи c и должен вернуть его для вызывающей стороны со статусом. Итак, изображение и строка. Это приложение было разработано в Swift. Другой называется ZipZag, который вызывает SincApp и ожидает вашего ответа, который должен показывать полученное изображение и строку состояния в метке, разработанной в Xamarin.

Я настроил Info.plist следующим образом:

Info.plist

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>sincapp-scan</string>
    </array>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>br.com.xxx.SincApp</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>sincapp-scan-back</string>
            </array>
        </dict>
    </array>


<key>UIApplicationSceneManifest</key>
<dict>
    <key>UIApplicationSupportsMultipleScenes</key>
    <false/>
</dict>
<key>UIRequiresFullScreen</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>SincApp</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>br.com.xxx.sincapp</string>
        </array>
    </dict>
</array>

Entitlement.plist так:

<key>com.apple.security.application-groups</key>
<array>
    <string>group.com.xxx.sincapp</string>
</array>

ScamCameraViewControler.cs

[Register("UniversalView")]
public class UniversalView : UIView
{
    public UniversalView()
    {
        Initialize();
    }

    public UniversalView(RectangleF bounds) : base(bounds)
    {
        Initialize();
    }

    void Initialize()
    {
        BackgroundColor = UIColor.Red;
    }
}

[Register("ScamCameraViewController")]
public class ScamCameraViewController : UIViewController
{

public ScamCameraViewController()
{
}

public override void DidReceiveMemoryWarning()
{

    base.DidReceiveMemoryWarning();


}

public override void ViewDidLoad()
{
    View = new UniversalView();

    base.ViewDidLoad();

    this.UIObserver();

    this.CallSincApp();


}


public async Task UIObserver()
{
    NSNotificationCenter
        .DefaultCenter
        .AddObserver(
            this, 
            new ObjCRuntime.Selector("handleEventNotification:"),
            new NSString("EventNotification"), 
            null);


}

[Export("handleEventNotification:")]
public void handleEventNotification(NSNotification obj)
{

    // var readValue = NSUserDefaults.StandardUserDefaults.StringForKey("CFBundleURLName");
    NSUserDefaults userDefaults = new NSUserDefaults("group.br.com.xxx.sincapp", NSUserDefaultsType.SuiteName);



    var isSincAppProcessSuccess = userDefaults.BoolForKey("KEY_STATUS"); 

    var isSincAppProcessSuccess2 = userDefaults.StringForKey(new NSString ("KEY_STATUS"));


}

public async Task CallSincApp()
{
    var application = UIApplication.SharedApplication;

    var SDK_KEY = "99999999999999999999999999999999";    

    var urlString = "sincapp-scan://?canoaKey=/" + SDK_KEY + "&scanbarcode=/";

    Foundation.NSUrl urlApp = Foundation.NSUrl.FromString(urlString);
    if (application.CanOpenUrl(urlApp))
    {
        application.OpenUrl(urlApp);
    }
}

}

AppDelegate.cs

// The UIApplicationDelegate for the application. This class is responsible for launching the 
// User Interface of the application, as well as listening (and optionally responding) to 
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
    //
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();


    LoadApplication(new App(new iOSInitializer()));


    return base.FinishedLaunching(app, options);
}



public override bool HandleOpenURL(UIApplication application, NSUrl url)
{
    BindValue(url);
    return true;
}

private void BindValue(NSUrl url)
{
    if (url.Scheme == "sincapp-scan-back")
    {
        NSNotificationCenter
            .DefaultCenter
            .PostNotificationName("EventNotification", null, null);
    }

}

public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
    // We need to handle URLs by passing them to their own OpenUrl in order to make the SSO authentication works.
    BindValue(url);
    return true;
}
        }

public class iOSInitializer : IPlatformInitializer
{
    public void RegisterTypes(IContainerRegistry containerRegistry)
    {
    // Register any platform specific implementations
    }
}

}

ScanCamera iOS

private async Task callMainViewController()
{
    ScamCameraViewController scvc = new ScamCameraViewController();
    scvc.ViewDidLoad();

}

Но когда я делаю это, var isSincAppProcessSuccess всегда возвращает false, а isSincAppProcessSuccess2 имеет значение null. Работает то же приложение, разработанное в Swift.

Кто-нибудь может мне помочь, пожалуйста?

...