NSInvalidArgumentException。 UIPasteboard setString

时间:2014-07-24 13:12:59

标签: ios objective-c xcode crash uipasteboard

通常应用程序效果很好,但我在Crashlytics中收到了问题。它每周发生1-2次。适用于2k-3k用户。应用程序适用于iOS 7及更高版本。 报告:致命异常:NSInvalidArgumentException

-[UIPasteboard setString:]: Argument is not an object of type NSString [(null)]

此处应用程序崩溃的线程堆栈:

 Thread : Crashed: com.apple.main-thread
 0  libsystem_kernel.dylib         0x38fae1f0 __pthread_kill + 8
 1  libsystem_pthread.dylib        0x390167b7 pthread_kill + 58
 2  libsystem_c.dylib              0x38f5eff9 abort + 76
 3  libc++abi.dylib                0x383ad98f abort_message + 74
 4  libc++abi.dylib                0x383c66e7 default_terminate_handler() + 254
 5  libobjc.A.dylib                0x389f9f7d _objc_terminate() + 192
 6  APPNAME                       0x001f1495 CPPExceptionTerminate() (KSCrashSentry_CPPException.mm:193)
 7  libc++abi.dylib                0x383c41b3 std::__terminate(void (*)()) + 78
 8  libc++abi.dylib                0x383c3a09 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
 9  libobjc.A.dylib                0x389f9dbb objc_exception_throw + 250
 10 CoreFoundation                 0x2e25ee0d -[NSException initWithCoder:]
 11 UIKit                          0x30e3e0eb -[UIPasteboard(UIPasteboardDataExtensions) setString:] + 154
 12 APPNAME                       0x0011cfaf __33-[WebViewController moreActions:]_block_invoke_2 (WebViewController.m:424)
 13 UIKit                          0x30c74ceb __56-[UIActivityViewController _cleanupActivityWithSuccess:]_block_invoke + 54
 14 UIKit                          0x30ba87c9 -[UIWindowController transitionViewDidComplete:fromView:toView:removeFromView:] + 1880
 15 UIKit                          0x30ba7f9f __101-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:]_block_invoke293 + 170
 16 UIKit                          0x30ba7ecb -[_UIViewControllerTransitionContext completeTransition:] + 74
 17 UIKit                          0x30ba7db1 -[UITransitionView notifyDidCompleteTransition:] + 288
 18 UIKit                          0x30ba78c1 -[UITransitionView _didCompleteTransition:] + 944
 19 UIKit                          0x30ac83b7 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 178
 20 UIKit                          0x30ac82cf -[UIViewAnimationState animationDidStop:finished:] + 66
 21 QuartzCore                     0x30712e0b CA::Layer::run_animation_callbacks(void*) + 234
 22 libdispatch.dylib              0x38ee2d3f _dispatch_client_callout + 22
 23 libdispatch.dylib              0x38ee56c3 _dispatch_main_queue_callback_4CF + 278
 24 CoreFoundation                 0x2e229641 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
 25 CoreFoundation                 0x2e227f0d __CFRunLoopRun + 1308
 26 CoreFoundation                 0x2e192729 CFRunLoopRunSpecific + 524
 27 CoreFoundation                 0x2e19250b CFRunLoopRunInMode + 106
 28 GraphicsServices               0x331016d3 GSEventRunModal + 138
 29 UIKit                          0x30af3871 UIApplicationMain + 1136
 30 APPNAME                       0x000b9287 main (main.m:16)

在函数moreActions中的WebViewController中使用了应用程序。

12 APPNAME    0x0011cfaf __33-[WebViewController moreActions:]_block_invoke_2 (WebViewController.m:424)

此功能显示 UIActivityViewController 和自定义操作之一 - 复制网页链接。

 __weak WebViewController *weakSelf = self;
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
    WebViewController *strongSelf = weakSelf;
    if ([activityType isEqualToString:@"VK"]) {
        // actions
    } else if ([activityType isEqualToString:@"copyLink"]) {

        // HERE UIPasteboard!
        UIPasteboard *pb = [UIPasteboard generalPasteboard];
        [pb setString:[strongSelf.startUrl absoluteString]];

    }
}];

1 个答案:

答案 0 :(得分:0)

确保[strongSelf.startUrl absoluteString]在将其设置为粘贴板字符串之前不返回nil。我很确定你的startUrl显然是零。