【问题标题】:iOS upload photoiOS上传照片
【发布时间】:2012-03-07 22:33:31
【问题描述】:

尝试在 Phonegap 中使用我的 iOS 应用上传照片时遇到问题。错误是:

2012-02-16 19:06:17.523 ContactExplorer[851:207] File Transfer Error: Invalid server URL
2012-02-16 19:06:17.623 ContactExplorer[851:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: target)'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x01dfb5a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x01f4f313 objc_exception_throw + 44
    2   CoreFoundation                      0x01db3ef8 +[NSException raise:format:arguments:] + 136
    3   CoreFoundation                      0x01db3e6a +[NSException raise:format:] + 58
    4   CoreFoundation                      0x01df9e15 -[__NSCFDictionary setObject:forKey:] + 293
    5   ContactExplorer                     0x00021990 -[PGFileTransfer createFileTransferError:AndSource:AndTarget:] + 153
    6   ContactExplorer                     0x00020c0b -[PGFileTransfer upload:withDict:] + 717
    7   ContactExplorer                     0x000157bf -[PhoneGapDelegate execute:] + 434
    8   ContactExplorer                     0x000029f0 -[AppDelegate execute:] + 80
    9   ContactExplorer                     0x000151e4 -[PhoneGapDelegate executeQueuedCommands] + 265
    10  ContactExplorer                     0x00015291 -[PhoneGapDelegate flushCommandQueue] + 81
    11  ContactExplorer                     0x00015600 -[PhoneGapDelegate webView:shouldStartLoadWithRequest:navigationType:] + 822
    12  ContactExplorer                     0x00002d3c -[AppDelegate webView:shouldStartLoadWithRequest:navigationType:] + 108
    13  UIKit                               0x00a93a92 -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:] + 291
    14  CoreFoundation                      0x01d6bc7d __invoking___ + 29
    15  CoreFoundation                      0x01d6bb51 -[NSInvocation invoke] + 145
    16  CoreFoundation                      0x01d99858 -[NSInvocation invokeWithTarget:] + 72
    17  WebKit                              0x0283cc76 -[_WebSafeForwarder forwardInvocation:] + 182
    18  CoreFoundation                      0x01d6ca04 ___forwarding___ + 1124
    19  CoreFoundation                      0x01d6c522 _CF_forwarding_prep_0 + 50
    20  CoreFoundation                      0x01d6bc7d __invoking___ + 29
    21  CoreFoundation                      0x01d6bb51 -[NSInvocation invoke] + 145
    22  WebCore                             0x03330150 _ZL20HandleDelegateSourcePv + 64
    23  CoreFoundation                      0x01ddc8ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    24  CoreFoundation                      0x01d3a88b __CFRunLoopDoSources0 + 571
    25  CoreFoundation                      0x01d39d86 __CFRunLoopRun + 470
    26  CoreFoundation                      0x01d39840 CFRunLoopRunSpecific + 208
    27  CoreFoundation                      0x01d39761 CFRunLoopRunInMode + 97
    28  GraphicsServices                    0x023781c4 GSEventRunModal + 217
    29  GraphicsServices                    0x02378289 GSEventRun + 115
    30  UIKit                               0x0090ac93 UIApplicationMain + 1160
    31  ContactExplorer                     0x0000246f main + 127
    32  ContactExplorer                     0x000023e5 start + 53
    33  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'

我用谷歌搜索了错误,但没有关于 key:target 的描述。

【问题讨论】:

    标签: ios cordova upload


    【解决方案1】:

    阅读更多关闭:

    [__NSCFDictionary setObject:forKey:]:尝试插入零值(键:目标)

    您正在尝试将 NIL 设置为某个字典对象。我们无法使用错误日志在您的代码中找到该位置。

    还要检查您是否将所有参数正确设置到您正在使用的对象中(您可以在堆栈跟踪中看到其中的几个)。其中一些可能发生了异常。

    * 更新: 当我看到这些行时:

    5   ContactExplorer                     0x00021990 -[PGFileTransfer createFileTransferError:AndSource:AndTarget:] + 153
    6   ContactExplorer                     0x00020c0b -[PGFileTransfer upload:withDict:] + 717
    7   ContactExplorer                     0x000157bf -[PhoneGapDelegate execute:] + 434
    

    我可以建议这个错误是在 PhoneGapDelegate 中产生的。它使用使用字典的 PGFileTransfer。然后崩溃。您提供的一些数据导致了这一点。问题也可能在于您的论点的早期实现。

    几行代码可以提供帮助。尤其是 PhoneGap 的创建、委托和自定义回调。

    【讨论】:

    • 我不太确定是这种情况。我的应用程序中没有字典对象或类似的东西。这是一个非常常见的错误,但键具有不同的值
    • 如果您没有明确使用任何字典,请参阅我回答的第二部分。
    • 您能否发布您正在使用的代码,因为我在尝试从 PhoneGap/SenchaTouch 应用程序上传文件时从未遇到过这种错误。
    猜你喜欢
    • 1970-01-01
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    相关资源
    最近更新 更多