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

时间:2018-08-29 14:24:56

标签: c# xamarin xamarin.ios snapkit xamarin.ios-binding

尝试在Xamarin.iOS中实现新的SnapChat Creative Kit,我使用Objective Sharpie绑定了SDK框架。在遵循其他SDK的官方文档(仅包含swift和obj-c的实现步骤)的同时,这不是问题-我成功实现了Login Kit-在尝试将内容发送到SnapChat时,我迷上了这段代码。 / p>

特别是在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是SCSDKSnapContent协议的实现。它提供了一种对照片快照进行建模以共享到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(这是一个抽象类),而不接受其实现,并且在调用它时出现错误:

  

CS1503参数1:无法从“ SCSDKCreativeKit_Bindings.SCSDKPhotoSnapContent”转换为“ SCSDKCreativeKit_Bindings.SCSDKSnapContent”

编辑:

ApiDefinition.cs

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

我尝试添加另一个这样的构造函数:

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

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

  

SnapEncryptionMetadataUnexpectedStatusCode

1 个答案:

答案 0 :(得分:2)

我找不到在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
});