Facebook和Twitter分享错误Swift

尝试在Facebook或Twitter上分享时遇到此错误。

2015-04-12 17:49:42.208 TestShareApp[1069:30252] *** Assertion failure in -[UICGColor encodeWithCoder:], /SourceCache/UIKit_Sim/UIKit-3347.44/UIColor.m:1448 2015-04-12 17:49:42.359 TestShareApp[1069:30252] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation.' *** First throw call stack: ( 0 CoreFoundation 0x0000000110424c65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010fce0bb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000110424aca +[NSException raise:format:arguments:] + 106 3 Foundation 0x000000010f24298f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195 4 UIKit 0x0000000110c8379a -[UIColor encodeWithCoder:] + 972 5 Foundation 0x000000010f1f13e5 _encodeObject + 1120 6 Foundation 0x000000010f1f0c49 +[NSKeyedArchiver archivedDataWithRootObject:] + 162 7 UIKit 0x0000000110f842f7 -[_UIAppearanceRecorder _recordInvocation:withClassName:containerClassNames:traitCollection:selectorString:forRemoteProcess:] + 1915 8 UIKit 0x0000000110f7ef5d __54+[_UIAppearance _recordersExcludingSource:withWindow:]_block_invoke + 907 9 CoreFoundation 0x0000000110364656 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102 10 CoreFoundation 0x000000011036455c -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 204 11 UIKit 0x0000000110f7ebc0 +[_UIAppearance _recordersExcludingSource:withWindow:] + 137 12 UIKit 0x000000011114897d UIViewServiceCurrentAppearanceSerializedRepresentations + 77 13 UIKit 0x000000011103bcc9 +[_UIRemoteViewController _requestViewController:traitCollection:fromServiceWithBundleIdentifier:service:connectionHandler:] + 232 14 UIKit 0x000000011103bbaa +[_UIRemoteViewController requestViewControllerWithService:connectionHandler:] + 91 15 UIKit 0x0000000110f13db8 __117-[NSExtension(UIViewControllerAdditions) instantiateViewControllerWithInputItems:listenerEndpoint:connectionHandler:]_block_invoke_2 + 621 16 libdispatch.dylib 0x000000011220e186 _dispatch_call_block_and_release + 12 17 libdispatch.dylib 0x000000011222d614 _dispatch_client_callout + 8 18 libdispatch.dylib 0x0000000112215a1c _dispatch_main_queue_callback_4CF + 1664 19 CoreFoundation 0x000000011038c1f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 20 CoreFoundation 0x000000011034ddcb __CFRunLoopRun + 2043 21 CoreFoundation 0x000000011034d366 CFRunLoopRunSpecific + 470 22 GraphicsServices 0x0000000113f81a3e GSEventRunModal + 161 23 UIKit 0x0000000110a4d900 UIApplicationMain + 1282 24 TestShareApp 0x000000010e38d457 main + 135 25 libdyld.dylib 0x0000000112261145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) 

这里是我的脸谱和微博动作片的代码

 func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) { if buttonIndex == 1 { // Facebook if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) { var controller = SLComposeViewController(forServiceType:SLServiceTypeFacebook) controller.setInitialText(shareText) controller.addURL(NSURL(string: appUrl) ) self.presentViewController(controller, animated: true, completion: nil) controller.completionHandler = { (result:SLComposeViewControllerResult) -> Void in switch result { case SLComposeViewControllerResult.Cancelled: println("fb cancel") case SLComposeViewControllerResult.Done: println("done") } } } else { var alert = UIAlertView(title: "No Facebook Account", message: "Oops, you've not added facebook account in your iphone settings", delegate: self, cancelButtonTitle: "Okay") alert.show() } } else if buttonIndex == 2 { // Twitter if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) { var controller = SLComposeViewController(forServiceType:SLServiceTypeTwitter) controller.setInitialText(shareText) controller.addURL(NSURL(string: appUrl) ) self.presentViewController(controller, animated: true, completion: nil) controller.completionHandler = { (result:SLComposeViewControllerResult) -> Void in switch result { case SLComposeViewControllerResult.Cancelled: println("fb cancel") case SLComposeViewControllerResult.Done: println("done") } } } else { var alert = UIAlertView(title: "No Twitter Account", message: "Oops! Looks like you've not added Twitter account in your settings", delegate: self, cancelButtonTitle: "Okay") alert.show() } } } 

相同的代码可以在我的其他应用程 不知道为什么这是发生在我单击或Facebook或Twitter时。