C# 绑定库方法不接受实现参数

C# Bound library method doesn't accept implementation parameter

尝试在 Xamarin.iOS 中实现新的 SnapChat Creative Kit,我使用 Objective Sharpie 绑定了 SDK 框架。在遵循其他 SDK 的官方文档(只有 swift 和 obj-c 的实现步骤)时,这不是问题 - 我成功实现了登录套件 - 我在尝试发送内容时遇到了这段代码到 SnapChat。

特别是,在 Documentation 中,要将内容发送到 api,使用此代码:

// swift

let snapImage = /* Set your image here */
let photo = SCSDKSnapPhoto(image: snapImage)

let snap = SCSDKSnapPhotoContent(snapPhoto: photo)

let api = SCSDKSnapAPI(content: snap)
api.startSnapping({ (error: Error?) in
/* Error handling */
})

根据文档,

SCSDKPhotoSnapContent is an implementation of the SCSDKSnapContent protocol. It provides a way to model a photo Snap for sharing to Snapchat.

这是我的 C# 实现:

var snapImage = GetCurrentScreenImage();
SCSDKSnapPhoto photo = new SCSDKSnapPhoto(snapImage);
SCSDKPhotoSnapContent snapPhoto = new SCSDKPhotoSnapContent(photo)

SCSDKSnapAPI api = new SCSDKSnapAPI(snapPhoto);
api.StartSnappingWithCompletionHandler((NSError error) =>
{
    // Error handling
});

问题是 SCSDKSnapAPI 构造函数只接受 SCSDKSnapContent,这是一个抽象 class,而不是它的实现,我在调用它时遇到错误:

CS1503 Argument 1: cannot convert from 'SCSDKCreativeKit_Bindings.SCSDKPhotoSnapContent' to 'SCSDKCreativeKit_Bindings.SCSDKSnapContent'

编辑:

ApiDefinition.cs

[Export("initWithContent:")]
IntPtr Constructor(SCSDKSnapContent content);

我试过像这样添加另一个构造函数:

[Export("initWithContent:SCSDKPhotoSnapContent")]
IntPtr Constructor(SCSDKPhtotoSnapContent content);

代码现在生成,但我在回调时从 SnapChat 收到以下错误代码:

SnapEncryptionMetadataUnexpectedStatusCode

我无法在 Xamarin.iOS 中找到正确实现 SCSDKSnapContent 的方法。我确实找到了一个解决方法,那种工作。如果您将绑定库中 SCSDKSnapAPI 的构造函数从 SCSDKSnapContent 更改为它的实现之一(在我的例子中是 SCSDKPhotoSnapContent),如下所示:

[Export("initWithContent:")]
IntPtr Constructor(SCSDKPhotoSnapContent content);

您可以在 Xamarin 中正确调用 SCSDKSnapAPI

var snapImage = GetCurrentScreenImage();
SCSDKSnapPhoto photo = new SCSDKSnapPhoto(snapImage);
SCSDKPhotoSnapContent snapPhoto = new SCSDKPhotoSnapContent(photo)

SCSDKSnapAPI api = new SCSDKSnapAPI(snapPhoto);
api.StartSnappingWithCompletionHandler((NSError error) =>
{
    // Error handling
});