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

问题描述 投票:2回答:1

尝试在Xamarin.iOS中实现新的SnapChat Creative Kit,我使用Objective Sharpie绑定了SDK框架。虽然遵循其他SDK的官方文档(其中只有swift和obj-c的实现步骤)不是问题 - 我成功实现了Login Kit - 在尝试将内容发送到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是SCSDKSnapContent协议的实现。它提供了一种模拟照片Snap以便与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

c# xamarin xamarin.ios snapkit xamarin.ios-binding
1个回答
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
});
© www.soinside.com 2019 - 2024. All rights reserved.