c# - Monotouch 的 Pinterest SDK 绑定(bind) - CreatePinWithImageURL 崩溃

标签 c# ios sdk xamarin.ios pinterest

我正在尝试为 Pinterest SDK 创建绑定(bind):

http://developers.pinterest.com/ios/

大部分 API 都有效; CanPinWithSDK 按预期正确返回 true/false

但是 CreatePinWithImageURL 总是崩溃。栈顶看起来像这样:

Feb  3 17:28:45 UK-IT-IPD-D0004 PinterestSDKDemo[8992] <Error>: Stacktrace:
Feb  3 17:28:45 UK-IT-IPD-D0004 PinterestSDKDemo[8992] <Error>:   at <unknown> <0xffffffff>
Feb  3 17:28:45 UK-IT-IPD-D0004 PinterestSDKDemo[8992] <Error>:   at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr_IntPtr (intptr,intptr,intptr,intptr,intptr) <0xffffffff>
Feb  3 17:28:45 UK-IT-IPD-D0004 PinterestSDKDemo[8992] <Error>:   at PinterestSDK.Pinterest.CreatePinWithImageURL (MonoTouch.Foundation.NSUrl,MonoTouch.Foundation.NSUrl,string) [0x0005f] in /Users/Alasdair/code/PinterestSDKBinding/PinterestSDKBinding/obj/Debug/ios/PinterestSDK/Pinterest.g.cs:154

绑定(bind)看起来像这样:

[Export ("createPinWithImageURL:sourceURL:description:")]
void CreatePinWithImageURL (NSUrl imageURL, NSUrl sourceURL, string descriptionText);

生成的代码如下所示:

[Export ("createPinWithImageURL:sourceURL:description:")]
[CompilerGenerated]
public virtual void CreatePinWithImageURL (NSUrl imageURL, NSUrl sourceURL, string descriptionText)
{
    if (imageURL == null)
        throw new ArgumentNullException ("imageURL");
    if (sourceURL == null)
        throw new ArgumentNullException ("sourceURL");
    if (descriptionText == null)
        throw new ArgumentNullException ("descriptionText");
    var nsdescriptionText = NSString.CreateNative (descriptionText);

    if (IsDirectBinding) {
        MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr_IntPtr (this.Handle, selCreatePinWithImageURLSourceURLDescription_Handle, imageURL.Handle, sourceURL.Handle, nsdescriptionText);
    } else {
        MonoTouch.ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr_IntPtr_IntPtr (this.SuperHandle, selCreatePinWithImageURLSourceURLDescription_Handle, imageURL.Handle, sourceURL.Handle, nsdescriptionText);
    }
    NSString.ReleaseNative (nsdescriptionText);

}

我的应用代码如下所示:

Pinterest pinterest = new Pinterest ("1234", "prod");
NSUrl imageUrl = new NSUrl(@"http://static.bbci.co.uk/frameworks/barlesque/2.59.12/orb/4/img/bbc-blocks-dark.png");
NSUrl sourceUrl = new NSUrl(@"http://www.bbc.co.uk");
pinterest.CreatePinWithImageURL (imageUrl, sourceUrl, "description");

它一碰到 void_objc_msgSend_IntPtr_IntPtr_IntPtr 就崩溃,无一异常(exception)

我已经在我的 info.plist 中设置了客户端 ID(从他们的演示应用程序中复制,它在 objective-c 中运行良好)。

有什么想法吗?有人成功地为这个 SDK 创建了绑定(bind)吗?

最佳答案

原来 PInterest 库有问题,你的崩溃来自这里:

Pinterest pinterest = new Pinterest ("1234", "prod");

PInterest 保留了一份 NSString 的副本。 (System.String 按需转换为它们)但它调用retain在他们。当您调用下一个 API(需要这些值)时,您会崩溃(因为它们已发布)。

这是一个错误 - 即使在 ObjC 中也是如此(如果您保留指向 NSObject 的指针引用,那么保留它是您的工作/职责)。大多数 ObjC 应用程序可能不会达到此目的,因为它们使用 NSString他们的应用程序中的常量(永远不会被释放的字段)。

解决方法是:

  1. 绑定(bind)initWithClientId:urlSchemeSuffix: API 使用 NSString (而不是 string );

  2. 保留 NSString "1234" 的实例和 "prod"只要你的 pinterest 还活着(例如静态字段)需要实例。

关于c# - Monotouch 的 Pinterest SDK 绑定(bind) - CreatePinWithImageURL 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21533841/

相关文章:

iphone - 如何在 ios 中创建自己的面具

ios loadNibNamed 到父类(super class)

javascript - 如何从过期的 Kuzzle token 服务器端恢复?

ios - SBStatusBarController 实例

c# - 不支持协议(protocol) 'net.tcp'

c# - 未经验证就发布

ios - Trigger.io 如何处理不同平台的条码扫描?

c# - Petapoco:操作可能会破坏运行时的稳定性

c# - 什么时候需要域名和域容器来创建 PrincipalContext?

android - 运行程序的主要功能