C# Bound library method doesn't accept implementation parameter

C# Bound library method doesn't accept implementation parameter



Trying to implement the new SnapChat Creative Kit in Xamarin.iOS, I bound the SDK framework using Objective Sharpie. While following the official documentation (which only has implementation steps for swift and obj-c) for other SDKs wan not a problem - I successfully implemented Login Kit - I came to a stumble with this code while trying to send the content to SnapChat.



In particular, in the Documentation, to send the contents to the api, this code is used:


// 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 */
)



According to the docs,



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



Here is my C# implementation:


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

SCSDKSnapAPI api = new SCSDKSnapAPI(snapPhoto);
api.StartSnappingWithCompletionHandler((NSError error) =>

// Error handling
);



The problem is SCSDKSnapAPI constructor only accepts SCSDKSnapContent, which is an abstract class, and not its implementation, and I get an error calling it:



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



EDIT:



ApiDefinition.cs


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



I tried adding another constructor like this:


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



The code now builds, but I receive the following error code from SnapChat on callback:



SnapEncryptionMetadataUnexpectedStatusCode





can you provide the code in ApiDefinition.cs?
– Lucas Zhang - MSFT
Aug 30 at 7:41





Added the constructor code. Let me know if more info is needed.
– ukie_
Aug 30 at 14:17




1 Answer
1



I couldn't find a way to correctly implement SCSDKSnapContent in Xamarin.iOS. I did find a workaround, that sort of works. If you change constructor for SCSDKSnapAPI in the binding library from SCSDKSnapContent to one of its implementations (SCSDKPhotoSnapContent in my case), like this:


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



You can then correctly call SCSDKSnapAPI in Xamarin


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

SCSDKSnapAPI api = new SCSDKSnapAPI(snapPhoto);
api.StartSnappingWithCompletionHandler((NSError error) =>

// Error handling
);



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế