Im getting an crash in my app when i am using UIActivityViewController here activityItems: [self.myimage.image!] :
let activityViewController = UIActivityViewController(
activityItems: [self.myimage.image!],
applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)
myimage is defined as UIImageView :
#IBOutlet weak var myimage: UIImageView!
The stack crash is here :
Thread 0 name:
Thread 0 Crashed:
0 MyPictures 0x000000010008e394 #objc MyPictures.DetailController.ActionShare (My.DetailController)(Swift.AnyObject) -> () + 540 (DetailController.swift:95)
1 UIKit 0x000000018a5f9400 -[UIApplication sendAction:to:from:forEvent:] + 92 (UIApplication.m:3452)
2 UIKit 0x000000018a5f9400 -[UIApplication sendAction:to:from:forEvent:] + 92 (UIApplication.m:3452)
3 UIKit 0x000000018a5e24dc -[UIControl _sendActionsForEvents:withEvent:] + 608 (UIControl.m:647)
4 UIKit 0x000000018a5f8d9c -[UIControl touchesEnded:withEvent:] + 588 (UIControl.m:417)
5 UIKit 0x000000018a5b7fbc _UIGestureRecognizerUpdate + 8532 (UIGestureRecognizer.m:347)
6 CoreFoundation 0x0000000185b3c2a0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28 (CFRunLoop.c:1622)
7 CoreFoundation 0x0000000185b3922c __CFRunLoopDoObservers + 356 (CFRunLoop.c:1718)
8 CoreFoundation 0x0000000185b3960c __CFRunLoopRun + 832 (CFRunLoop.c:2548)
9 CoreFoundation 0x0000000185a652d0 CFRunLoopRunSpecific + 392 (CFRunLoop.c:2795)
10 GraphicsServices 0x000000018f27b6f8 GSEventRunModal + 164 (GSEvent.c:2245)
11 UIKit 0x000000018a62afa8 UIApplicationMain + 1484 (UIApplication.m:3039)
12 MyPictures 0x0000000100091acc main + 152 (AppDelegate.swift:12)
13 libdyld.dylib 0x0000000197a26a04 start + 0 (start_glue.s:78)
It seems like the image is nil that generates a crash, so you should update your code like this:
if let image = self.myimage.image{
let activityViewController = UIActivityViewController(
activityItems: [image],
applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)
} else{
// Show some kind of error
}
Related
I am getting too many crashes from my users for scroll to bottom. What can be cause to this problem?
I am scrolling to bottom my tableview when keyboard appears. And this causes to crash. My code:
func keyboardWillShow(notification: NSNotification) {
var info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
self.view.layoutIfNeeded()
UIView.animateWithDuration(0.2) {
self.bottomCons.constant = keyboardFrame.size.height
self.view.layoutIfNeeded()
}
let numberOfRows = tableView.numberOfRowsInSection(0)
if numberOfRows != 0 {
do {
try tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: numberOfRows-1, inSection: 0), atScrollPosition: .Bottom, animated: false) //This line is crashing
}catch {
print("error")
}
}
}
Crash log:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000010013e018
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 Ribony 0x000000010013e018 specialized ChatViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell + 1904 (ChatViewController.swift:0)
1 Ribony 0x0000000100135890 #objc ChatViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell + 76 (ChatViewController.swift:0)
2 UIKit 0x000000018e315b58 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 716 (UITableView.m:10665)
3 UIKit 0x000000018e315e00 -[UITableView _createPreparedCellForRowAtIndexPath:willDisplay:] + 88 (UITableView.m:10717)
4 UIKit 0x000000018e31b4a8 -[UITableView _heightForRowAtIndexPath:] + 256 (UITableView.m:12615)
5 UIKit 0x000000018e1127c4 -[UISectionRowData heightForRow:inSection:canGuess:] + 280 (UITableViewRowData.m:288)
6 UIKit 0x000000018e4a413c -[UITableViewRowData ensureHeightsFaultedInForIndexPath:availHeight:edgeInset:scrollPosition:] + 1484 (UITableViewRowData.m:2418)
7 UIKit 0x000000018e1ef4f8 -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:] + 1792 (UITableView.m:5544)
8 UIKit 0x000000018e1eecb0 -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] + 52 (UITableView.m:5644)
9 Ribony 0x000000010013ed00 specialized ChatViewController.keyboardWillShow(NSNotification) -> () + 800 (ChatViewController.swift:550)
10 Ribony 0x0000000100136e98 #objc ChatViewController.keyboardWillShow(NSNotification) -> () + 56 (ChatViewController.swift:0)
11 CoreFoundation 0x00000001880b6b10 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 (CFNotificationCenter.c:650)
12 CoreFoundation 0x00000001880b6214 _CFXRegistrationPost + 400 (CFNotificationCenter.c:164)
13 CoreFoundation 0x00000001880b5f90 ___CFXNotificationPost_block_invoke + 60 (CFNotificationCenter.c:1031)
14 CoreFoundation 0x0000000188125b8c -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1504 (CFXNotificationRegistrar.m:163)
15 CoreFoundation 0x0000000187ff7e64 _CFXNotificationPost + 376 (CFNotificationCenter.c:1028)
16 Foundation 0x0000000188b2ce0c -[NSNotificationCenter postNotificationName:object:userInfo:] + 68 (NSNotification.m:482)
17 UIKit 0x000000018e9a6b40 -[UIInputWindowController postStartNotifications:withInfo:] + 400 (UIInputWindowController.m:1375)
18 UIKit 0x000000018e9a8cf0 __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.907 + 388 (UIInputWindowController.m:1816)
19 UIKit 0x000000018e0080f0 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 636 (UIView.m:11811)
20 UIKit 0x000000018e0d952c +[UIView(UIViewAnimationWithBlocks) _animateWithDuration:delay:options:animations:start:completion:] + 128 (UIView.m:11865)
21 UIKit 0x000000018e9a876c -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1368 (UIInputWindowController.m:1877)
22 UIKit 0x000000018e9af268 -[UIInputWindowController setInputViewSet:] + 1444 (UIInputWindowController.m:2923)
23 UIKit 0x000000018e9a7e38 -[UIInputWindowController performOperations:withAnimationStyle:] + 56 (UIInputWindowController.m:1674)
24 UIKit 0x000000018e099278 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1276 (UIPeripheralHost.m:4647)
25 UIKit 0x000000018dff8a78 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 80 (UIResponder.m:1107)
26 UIKit 0x000000018e056b4c -[UIResponder becomeFirstResponder] + 600 (UIResponder.m:272)
27 UIKit 0x000000018e056ebc -[UIView(Hierarchy) becomeFirstResponder] + 148 (UIView.m:9419)
28 UIKit 0x000000018e0d90b4 -[UITextField becomeFirstResponder] + 60 (UITextField.m:1396)
29 UIKit 0x000000018e180128 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 192 (UITextInteractionAssistant.m:1160)
30 UIKit 0x000000018e17f630 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 3024 (UITextInteractionAssistant.m:1770)
31 UIKit 0x000000018e59af80 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64 (UIGestureRecognizer.m:103)
32 UIKit 0x000000018e59e688 _UIGestureRecognizerSendTargetActions + 124 (UIGestureRecognizer.m:986)
33 UIKit 0x000000018e16573c _UIGestureRecognizerSendActions + 260 (UIGestureRecognizer.m:1020)
34 UIKit 0x000000018e0040f0 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 764 (UIGestureRecognizer.m:1067)
35 UIKit 0x000000018e58e680 _UIGestureEnvironmentUpdate + 1100 (UIGestureEnvironment.m:148)
36 UIKit 0x000000018e58e1e0 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 408 (UIGestureEnvironment.m:1181)
37 UIKit 0x000000018e58d49c -[UIGestureEnvironment _updateGesturesForEvent:window:] + 268 (UIGestureEnvironment.m:1090)
38 UIKit 0x000000018e00230c -[UIWindow sendEvent:] + 2960 (UIWindow.m:2289)
39 UIKit 0x000000018dfd2da0 -[UIApplication sendEvent:] + 340 (UIApplication.m:10729)
40 UIKit 0x000000018e7bc75c __dispatchPreprocessedEventFromEventQueue + 2736 (UIEventDispatcher.m:1430)
41 UIKit 0x000000018e7b6130 __handleEventQueue + 784 (UIEventDispatcher.m:1626)
42 CoreFoundation 0x00000001880cab5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1943)
43 CoreFoundation 0x00000001880ca4a4 __CFRunLoopDoSources0 + 524 (CFRunLoop.c:1989)
44 CoreFoundation 0x00000001880c80a4 __CFRunLoopRun + 804 (CFRunLoop.c:2821)
45 CoreFoundation 0x0000000187ff62b8 CFRunLoopRunSpecific + 444 (CFRunLoop.c:3113)
46 GraphicsServices 0x0000000189aaa198 GSEventRunModal + 180 (GSEvent.c:2245)
47 UIKit 0x000000018e03d7fc -[UIApplication _run] + 684 (UIApplication.m:2650)
48 UIKit 0x000000018e038534 UIApplicationMain + 208 (UIApplication.m:4092)
49 Ribony 0x00000001000ce070 main + 120 (AppDelegate.swift:15)
50 libdyld.dylib 0x0000000186fd95b8 start + 4
As you can see i am using this in a try catch block. It should not crash. How is this possible?
Try this code
func keyboardWillShow(notification: NSNotification) {
var info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
self.view.layoutIfNeeded()
UIView.animateWithDuration(0.2) {
self.bottomCons.constant = keyboardFrame.size.height
self.view.layoutIfNeeded()
}
tableViewScrollToBottom(true)
}
func tableViewScrollToBottom(animated: Bool) {
let delay = 0.2 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), {
let numberOfSections = self.tableView.numberOfSections()
let numberOfRows = self.tableView.numberOfRowsInSection(numberOfSections-1)
if numberOfRows > 0 {
let indexPath = NSIndexPath(forRow: numberOfRows-1, inSection: (numberOfSections-1))
self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: animated)
}
})
}
I am trying to show my "ProtectedViewController".
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller: UIViewController = storyboard.instantiateViewController(withIdentifier: "Protected") as! ProtectedPageViewController
self.present(controller, animated: true, completion: nil)
When i try to display it error pops on the step
self.present(controller, animated: true, completion: nil)
as on Screenshot below:
Code below isn't working too:
let pvc = ProtectedPageViewController()
self.present(pvc, animated: true, completion: nil)
The same error.Have tried everything.
Error from stack trace:
*** First throw call stack:
(
0 CoreFoundation 0x0000000108a2c34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010807021e objc_exception_throw + 48
2 CoreFoundation 0x0000000108a30442 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000107c06edd -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000109be1942 -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] + 165
5 UIKit 0x000000010934ec14 -[UIKeyboardImpl setDelegate:force:] + 1404
6 UIKit 0x0000000109776152 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 981
7 UIKit 0x000000010977f95c -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 498
8 UIKit 0x00000001092409b7 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1178
9 UIKit 0x0000000109242702 -[UIViewController _presentViewController:withAnimationController:completion:] + 4971
10 UIKit 0x00000001092456df -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
11 UIKit 0x00000001092451c5 -[UIViewController presentViewController:animated:completion:] + 179
12 Registration 0x0000000107a7208a _TFFC12Registration23LoginPageViewController17loginButtonTappedFPs9AnyObject_T_U_FTGSqV10Foundation4Data_GSqCSo11URLResponse_GSqPs5Error___T_ + 3482
13 Registration 0x0000000107a695fb _TTRXFo_oGSqV10Foundation4Data_oGSqCSo11URLResponse_oGSqPs5Error____XFdCb_dGSqCSo6NSData_dGSqS1__dGSqCSo7NSError___ + 203
14 CFNetwork 0x000000010b8756b0 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
15 CFNetwork 0x000000010b874f5c __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 308
16 Foundation 0x0000000107b742cd __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
17 Foundation 0x0000000107b73faf -[NSBlockOperation main] + 101
18 Foundation 0x0000000107b726ac -[__NSOperationInternal _start:] + 672
19 Foundation 0x0000000107b6e5ef __NSOQSchedule_f + 201
20 libdispatch.dylib 0x000000010c2600cd _dispatch_client_callout + 8
21 libdispatch.dylib 0x000000010c23de6b _dispatch_queue_serial_drain + 236
22 libdispatch.dylib 0x000000010c23eb9f _dispatch_queue_invoke + 1073
23 libdispatch.dylib 0x000000010c2413b7 _dispatch_root_queue_drain + 720
24 libdispatch.dylib 0x000000010c24108b _dispatch_worker_thread3 + 123
25 libsystem_pthread.dylib 0x000000010c60a712 _pthread_wqthread + 1299
26 libsystem_pthread.dylib 0x000000010c60a1ed start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Please help me to find the way to fix it.
Thanks in advance!!!
P.S.: Using iOS 10.0 and Swift 3
The stacktrace shows something in NSURLSession context. Are you presenting the ViewController from within the main thread, or from some worker thread?
Please check if executing your presentation call from the main thread succeeds:
DispatchQueue.main.async {
// here your presentation call, e.g.
self.present(controller, animated: true, completion: nil)
}
If not, you should post the complete exception (from the output window) and/or a little more code (more of the area you present the controller)
My app is crashing (only for some users) when they click on Share. This is the code:
#IBAction func btnShare(sender: AnyObject) {
let message = "Some message"
let shareUrl = "mydomain://someurl/\(someid)"
if let url = NSURL(string: shareUrl) {
let objectsToShare = [message, url]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList]
activityVC.popoverPresentationController?.sourceView = sender as! UIView
self.presentViewController(activityVC, animated: true, completion: nil)
}
}
This is the crash report:
Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x184a32014 __pthread_kill + 8
1 libsystem_pthread.dylib 0x184af9460 pthread_kill + 112
2 libsystem_c.dylib 0x1849a63f4 abort + 140
3 libswiftCore.dylib 0x100d83928 swift::fatalError(char const*, ...) + 50
4 libswiftCore.dylib 0x100d6c0f0 swift::swift_dynamicCastFailure(void const*, char const*, void const*, char const*, char const*) + 70
5 libswiftCore.dylib 0x100d6c180 swift::swift_dynamicCastFailure(swift::Metadata const*, swift::Metadata const*, char const*) + 142
6 libswiftCore.dylib 0x100d92460 swift_dynamicCastObjCClassUnconditional + 68
7 Wize 0x100117198 specialized MyViewController.btnShare(AnyObject) -> () (MyViewController.swift:363)
8 Wize 0x1001132b0 #objc MyViewController.btnShare(AnyObject) -> () (MyViewController.swift)
9 UIKit 0x18b8e27b0 -[UIApplication sendAction:to:from:forEvent:] + 96
10 UIKit 0x18ba565ec -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 168
11 UIKit 0x18b8e27b0 -[UIApplication sendAction:to:from:forEvent:] + 96
12 UIKit 0x18b8e2730 -[UIControl sendAction:to:forEvent:] + 80
13 UIKit 0x18b8ccbe4 -[UIControl _sendActionsForEvents:withEvent:] + 452
14 UIKit 0x18b8ccd4c -[UIControl _sendActionsForEvents:withEvent:] + 812
15 UIKit 0x18b8e201c -[UIControl touchesEnded:withEvent:] + 584
16 UIKit 0x18b8e1b44 -[UIWindow _sendTouchesForEvent:] + 2484
17 UIKit 0x18b8dcd8c -[UIWindow sendEvent:] + 2988
18 UIKit 0x18b8ad858 -[UIApplication sendEvent:] + 340
19 UIKit 0x18c09acb8 __dispatchPreprocessedEventFromEventQueue + 2736
20 UIKit 0x18c094720 __handleEventQueue + 784
21 CoreFoundation 0x185a12278 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
22 CoreFoundation 0x185a11bc0 __CFRunLoopDoSources0 + 524
23 CoreFoundation 0x185a0f7c0 __CFRunLoopRun + 804
24 CoreFoundation 0x18593e048 CFRunLoopRunSpecific + 444
25 GraphicsServices 0x1873c1198 GSEventRunModal + 180
26 UIKit 0x18b918628 -[UIApplication _run] + 684
27 UIKit 0x18b913360 UIApplicationMain + 208
28 Wize 0x1001208f4 main (AppDelegate.swift:19)
29 libdispatch.dylib 0x1849205b8 (Missing)
Any idea what may be going on? It works fine for half the users.
To check the sender before converting it:
guard let sourceView = sender as? UIView else {
return
}
...
activityVC.popoverPresentationController?.sourceView = sourceView
For this below line
activityVC.popoverPresentationController?.sourceView = sender as! UIView
add this line
if let senderSourceView = sender as? UIView {
activityVC.popoverPresentationController?.sourceView = senderSourceView
}else{
//Here not getting UIView
}
It's possible App crash because if UIView not get for sourceView.It is work if right as i said.
This is the crash log I got from Crashlytics:
Thread : Crashed: com.apple.main-thread
0 Trenìt! 0x1000b93e4 SearchHistoryProvider.getMostRecentStations(Int) -> [String] (SearchHistoryProvider.swift)
1 Trenìt! 0x10007985c specialized MasterViewController.onTouchedTextField(UITextField) -> () (MasterViewController.swift:265)
2 Trenìt! 0x100075414 #objc MasterViewController.onTouchedTextField(UITextField) -> () (MasterViewController.swift)
3 UIKit 0x186fa0ad0 -[UIApplication sendAction:to:from:forEvent:] + 100
4 UIKit 0x186fa0a4c -[UIControl sendAction:to:forEvent:] + 80
5 UIKit 0x186f88740 -[UIControl _sendActionsForEvents:withEvent:] + 436
6 UIKit 0x186fa9248 -[UIControl touchesBegan:withEvent:] + 400
7 UIKit 0x186f9fdc0 -[UIWindow _sendTouchesForEvent:] + 376
8 UIKit 0x186f98b08 -[UIWindow sendEvent:] + 784
9 UIKit 0x186f68f4c -[UIApplication sendEvent:] + 248
10 UIKit 0x186f67528 _UIApplicationHandleEventQueue + 6568
11 CoreFoundation 0x181dd5124 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
12 CoreFoundation 0x181dd4bb8 __CFRunLoopDoSources0 + 540
13 CoreFoundation 0x181dd28b8 __CFRunLoopRun + 724
14 CoreFoundation 0x181cfcd10 CFRunLoopRunSpecific + 384
15 GraphicsServices 0x1835e4088 GSEventRunModal + 180
16 UIKit 0x186fd1f70 UIApplicationMain + 204
17 Trenìt! 0x10009b2fc main (AppDelegate.swift:14)```
(edited)
and this is my code:
MasterViewController.swift:
263 func showRecentStations(textField: UITextField) {
264 textField.text = ""
265 suggestionStations = masterContainerManager!.homeController?.searchHistoryProvider?.getMostRecentStations(10)
266 updateStationsTable(textField)
267 }
SearchHistoryProvider.swift
func getMostRecentStations (maxSize : Int) -> [String] {
let stationsByOldestArray = getRecentStationsByOldest()
let stations = NSMutableOrderedSet()
for i in (0...(stationsByOldestArray.count-1)).reverse() {
stations.addObject(stationsByOldestArray[i].depStation)
if stations.count==maxSize {
return stations.array as! [String]
}
stations.addObject(stationsByOldestArray[i].arrStation)
if stations.count==maxSize {
return stations.array as! [String]
}
}
return stations.array as! [String]
}
Can anyone understand what's the crash about?
I found the bug:
in case stationsByOldestArray.count was 0
the for loop would have been
for i in (0...-1).reverse()
I fixed it by rewriting the loop as
for i in (0..<stationsByOldestArray.count).reverse()
However I think the Swift crash reports are often hopelessly unhelpful!
I have an activity controller, which sometimes crashes and I dont understand why. This is my code:
func screenShotMethod() {
//Create the UIImage
let image = view?.snapshot
//Save it to the camera roll
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
self.socialShare(sharingText: "text", sharingImage: image, sharingURL:NSURL(string: "itms-apps://itunes.apple.com/app/bars/XXXXXXXX"))
}
func socialShare(#sharingText: String?, sharingImage: UIImage?, sharingURL: NSURL?) {
var sharingItems = [AnyObject]()
if let text = sharingText {
sharingItems.append(text)
}
if let image = sharingImage {
sharingItems.append(image)
}
if let url = sharingURL {
sharingItems.append(url)
}
let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypeCopyToPasteboard,UIActivityTypeAirDrop,UIActivityTypeAddToReadingList,UIActivityTypeAssignToContact,UIActivityTypePostToTencentWeibo,UIActivityTypePostToVimeo,UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypePostToWeibo]
var currentViewController:UIViewController=UIApplication.sharedApplication().keyWindow!.rootViewController!
currentViewController.presentViewController(activityViewController, animated: true, completion: nil)
shareButton.alpha = 1.0
}
and here is my UIView snapshot extension:
extension UIView {
var snapshot: UIImage {
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)
drawViewHierarchyInRect(bounds, afterScreenUpdates: true)
let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return result
}
}
and here are the errors I am getting:
Thread : Fatal Exception: NSGenericException
0 CoreFoundation 0x25a14fef __exceptionPreprocess
1 libobjc.A.dylib 0x33e00c8b objc_exception_throw
2 UIKit 0x2970ae63 -[UIPopoverPresentationController presentationTransitionWillBegin]
3 UIKit 0x2934209d __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke
4 UIKit 0x29340a17 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke
5 UIKit 0x290e4a91 _applyBlockToCFArrayCopiedToStack
6 UIKit 0x2905f38f _afterCACommitHandler
7 CoreFoundation 0x259dafed __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
8 CoreFoundation 0x259d86ab __CFRunLoopDoObservers
9 CoreFoundation 0x259d8ab3 __CFRunLoopRun
10 CoreFoundation 0x25925201 CFRunLoopRunSpecific
11 CoreFoundation 0x25925013 CFRunLoopRunInMode
12 GraphicsServices 0x2d101201 GSEventRunModal
13 UIKit 0x290c9a59 UIApplicationMain
14 A Void 0x000ba600 main (AppDelegate.swift:19)
15 libdyld.dylib 0x3438caaf start
and
Thread : Crashed: com.apple.main-thread
0 A Void 0x0013aa90 function signature specialization <Arg[0] = Owned To Guaranteed and Exploded, Arg[1] = Owned To Guaranteed, Arg[2] = Owned To Guaranteed> of A_Void.GameScene.touchesMoved (A_Void.GameScene)(Swift.Set<ObjectiveC.NSObject>, withEvent : ObjectiveC.UIEvent) -> () (GameScene.swift:2036)
1 A Void 0x0013a950 function signature specialization <Arg[0] = Owned To Guaranteed and Exploded, Arg[1] = Owned To Guaranteed, Arg[2] = Owned To Guaranteed> of A_Void.GameScene.touchesMoved (A_Void.GameScene)(Swift.Set<ObjectiveC.NSObject>, withEvent : ObjectiveC.UIEvent) -> () (GameScene.swift:2026)
2 A Void 0x0010b2bc #objc A_Void.GameScene.touchesMoved (A_Void.GameScene)(Swift.Set<ObjectiveC.NSObject>, withEvent : ObjectiveC.UIEvent) -> () (GameScene.swift)
3 SpriteKit 0x28f0a8af -[SKView touchesMoved:withEvent:] + 710
4 UIKit 0x2909a46b -[UIWindow _sendTouchesForEvent:] + 350
5 UIKit 0x29093df1 -[UIWindow sendEvent:] + 544
6 UIKit 0x29069fe5 -[UIApplication sendEvent:] + 196
7 UIKit 0x292e08fb _UIApplicationHandleEventFromQueueEvent + 14414
8 UIKit 0x290689f9 _UIApplicationHandleEventQueue + 1352
9 CoreFoundation 0x259dafaf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
10 CoreFoundation 0x259da3bf __CFRunLoopDoSources0 + 218
11 CoreFoundation 0x259d8a25 __CFRunLoopRun + 772
12 CoreFoundation 0x25925201 CFRunLoopRunSpecific + 476
13 CoreFoundation 0x25925013 CFRunLoopRunInMode + 106
14 GraphicsServices 0x2d101201 GSEventRunModal + 136
15 UIKit 0x290c9a59 UIApplicationMain + 1440
16 A Void 0x0014d600 main (AppDelegate.swift:19)
17 libdyld.dylib 0x3438caaf start + 2
The app is a game made with sprite kit, so I am calling this game method inside SKScene. Also, the game game view controller is the one controlling game scene and it is embed navigation view controller, in which I present gamecenter. Anyone nows how to fix this?