2

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

ukie_
  • 116
  • 6

1 Answers1

2

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
});
ukie_
  • 116
  • 6