I am trying to call a 3rd Party API when a Client goes to a specific route using Swift and Vapor 3; however, I am met with errors despite being able to make the call.
I have taken steps to ensure the error is caused by the get request to the API. Currently, I do nothing with the request other than print the response. Removing the request stops the error from happening.
// Route the user to HomePage
router.get { req -> Future<View> in
let token: String = "THATS_MY_TOKEN"
let client = try req.client()
let bcmsrequest = try client.get("https://api.buttercms.com/v2/posts/?page=1&page_size=10&auth_token=" + token)
print(bcmsrequest)
print("This line prints.")
// Removing the above get request stops the error below from happening
return try req.view().render("welcome")
}
// Here is the stdout printed by the server process:
Server starting on http://localhost:8080
NIO.EventLoopFuture<Vapor.Response>
This line prints.
2019-07-27 11:49:12.249196-0400 Run[6348:121267] [] nw_endpoint_get_type called with null endpoint
2019-07-27 11:49:12.249420-0400 Run[6348:121267] [] nw_endpoint_get_type called with null endpoint, dumping backtrace:
[x86_64] libnetcore-1872
0 libnetwork.dylib 0x00007fff6d188fc8 __nw_create_backtrace_string + 120
1 libnetwork.dylib 0x00007fff6ce12af4 nw_endpoint_get_type + 180
2 libboringssl.dylib 0x00007fff6b6e3af2 nw_protocol_boringssl_get_subject_name + 178
3 libboringssl.dylib 0x00007fff6b6e6997 nw_protocol_boringssl_connected + 916
4 libnetwork.dylib 0x00007fff6ce5d145 nw_socket_handle_socket_event + 1733
5 libdispatch.dylib 0x00000001017fd82f _dispatch_client_callout + 8
6 libdispatch.dylib 0x0000000101800689 _dispatch_continuation_pop + 585
7 libdispatch.dylib 0x0000000101816608 _dispatch_source_invoke + 2135
8 libdispatch.dylib 0x0000000101807665 _dispatch_workloop_invoke + 3477
9 libdispatch.dylib 0x0000000101813025 _dispatch_workloop_worker_thread + 676
10 libsystem_pthread.dylib 0x000000010188f343 _pthread_wqthread.cold.1 + 125
11 libsystem_pthread.dylib 0x0000000101889196 _pthread_wqthread + 203
12 libsystem_pthread.dylib 0x0000000101889057 start_wqthread + 15
I can see that a Future Object is being printed out, I would expect to see response content (a JSON string) - but I believe that the response has no content and is actually failing to make a request at all.
I can see that a Future Object is being printed out, I would expect to see response content
So this is the crux of the problem. Because Vapor is asynchronous, you're printing the Future<Response> as soon as you send the request, meaning it hasn't returned yet. If you change it to:
router.get { req -> Future<View> in
let token: String = "THATS_MY_TOKEN"
let client = try req.client()
let bcmsrequest = try client.get("https://api.buttercms.com/v2/posts/?page=1&page_size=10&auth_token=" + token)
return bcmsrequest.flatMap { response in
print(response)
return try req.view().render("welcome")
}
}
You'll see the full response body and see what errors you're getting (if any)
Related
I'm having an issue where our application is crashing when the user taps the profile picture to upload their photo to the app. The app sends an authorization request to the user, and this crash happens immediantly once the "allow" button is tapped.
Maybe relevant information is that this is not the root view controller. The registration process has a series of pages on the same Storyboard. This is occuring on any page where I need to request permissions that isn't the main root controller.
I have attempted to place the PhotoAuthorization block of code into a DispatchQueue.main.async, but that didn't seem to work. This is legacy code by a former developer, so I'm still working on fixing up some stuff.
Code block suspected of crashing the app:
func checkPermission() {
let photoAuthStatus = PHPhotoLibrary.authorizationStatus()
switch photoAuthStatus {
case .authorized:
self.showPhotoActionSheet()
case .notDetermined:
PHPhotoLibrary.requestAuthorization({ (newStatus) in
if newStatus == PHAuthorizationStatus.authorized {
self.showPhotoActionSheet()
}
})
case .restricted:
showPermissionRequestReason()
case .denied:
showPermissionRequestReason()
}
}
func showPhotoActionSheet() {
let actionSheet = YoutubeActionController()
actionSheet.addAction(Action(ActionData(title: "Take Photo", image: UIImage(named: "ic_photo_camera")!), style: .default, handler: { action in
if UIImagePickerController.isSourceTypeAvailable(.camera) {
self.imagePicker.sourceType = .camera
self.imagePicker.allowsEditing = true
self.present(self.imagePicker, animated: true, completion: nil)
}
}))
actionSheet.addAction(Action(ActionData(title: "Choose from Camera Roll", image: UIImage(named: "ic_photo_album")!), style: .default, handler: { action in
if UIImagePickerController.isSourceTypeAvailable(.savedPhotosAlbum) {
self.imagePicker.sourceType = .savedPhotosAlbum
self.imagePicker.allowsEditing = true
self.present(self.imagePicker, animated: true, completion: nil)
}
}))
actionSheet.addAction(Action(ActionData(title: "Cancel", image: UIImage(named: "ic_cancel")!), style: .cancel, handler: nil))
present(actionSheet, animated: true, completion: nil)
}
Find the traceback below. Any help is greatly appreciated!
2020-01-23 13:39:23.878772+0000 ***[89799:17598462] *** Assertion failure in -[FBSSerialQueue assertOnQueue], /BuildRoot/Library/Caches/com.apple.xbs/Sources/FrontBoardServices_Sim/FrontBoard-626.2/FrontBoardServices/FBSSerialQueue.m:98
2020-01-23 13:39:23.990535+0000 ***[89799:17598462] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'threading violation: expected the main thread'
*** First throw call stack:
(
0 CoreFoundation 0x0000000115f7102e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x0000000115ddeb20 objc_exception_throw + 48
2 CoreFoundation 0x0000000115f70da8 +[NSException raise:format:arguments:] + 88
3 Foundation 0x000000010f613b61 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 FrontBoardServices 0x000000011c344a8b -[FBSSerialQueue assertOnQueue] + 236
5 FrontBoardServices 0x000000011c2f77b9 -[FBSSceneImpl updateClientSettings:withTransitionContext:] + 70
6 FrontBoardServices 0x000000011c2f7a04 -[FBSSceneImpl updateClientSettingsWithTransitionBlock:] + 154
7 FrontBoardServices 0x000000011c2f7929 -[FBSSceneImpl updateClientSettingsWithBlock:] + 110
8 UIKitCore 0x00000001200c7aa0 -[FBSScene(UIApp) updateUIClientSettingsWithBlock:] + 160
9 UIKitCore 0x000000011fcbf5f6 -[_UISystemAppearanceManager updateScreenEdgesDeferringSystemGestures] + 374
10 UIKitCore 0x000000011ff229e2 __70-[UIViewController setNeedsUpdateOfScreenEdgesDeferringSystemGestures]_block_invoke_2 + 118
11 UIKitCore 0x000000011ff00cb5 -[UIViewController _updateSystemAppearanceWithRecursionBlock:action:] + 295
12 UIKitCore 0x000000011ff22629 -[UIViewController _setPresentedStatusBarViewController:] + 220
13 UIKitCore 0x000000011ff129c3 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1381
14 UIKitCore 0x000000011ff143c6 -[UIViewController _presentViewController:withAnimationController:completion:] + 4349
15 UIKitCore 0x000000011ff16c47 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98
16 UIKitCore 0x000000011ff1715f -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511
17 UIKitCore 0x000000011ff16ba5 -[UIViewController _presentViewController:animated:completion:] + 187
18 UIKitCore 0x000000011ff16e0c -[UIViewController presentViewController:animated:completion:] + 150
19 *** 0x000000010dc472ca $s14***26RegistrationViewControllerC20showPhotoActionSheetyyF + 2522
20 *** 0x000000010dc462b9 $s14***26RegistrationViewControllerC15checkPermissionyyFySo21PHAuthorizationStatusVcfU_ + 201
21 *** 0x000000010dc46355 $sSo21PHAuthorizationStatusVIegy_ABIeyBy_TR + 53
22 Photos 0x0000000116a72643 __39+[PHPhotoLibrary requestAuthorization:]_block_invoke + 52
23 AssetsLibraryServices 0x000000013927ff7e __79-[PLPrivacy _isPhotosAccessAllowedWithScope:forceHandler:accessAllowedHandler:]_block_invoke.14 + 501
24 AssetsLibraryServices 0x000000013924b60c __pl_dispatch_async_block_invoke + 25
25 libdispatch.dylib 0x0000000117a02848 _dispatch_call_block_and_release + 12
26 libdispatch.dylib 0x0000000117a037b9 _dispatch_client_callout + 8
27 libdispatch.dylib 0x0000000117a09526 _dispatch_lane_serial_drain + 707
28 libdispatch.dylib 0x0000000117a09f5c _dispatch_lane_invoke + 388
29 libdispatch.dylib 0x0000000117a13ff9 _dispatch_workloop_worker_thread + 626
30 libsystem_pthread.dylib 0x00007fff51bfd611 _pthread_wqthread + 421
31 libsystem_pthread.dylib 0x00007fff51bfd3fd start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The error tells you want to do:
reason: 'threading violation: expected the main thread'
Many times, when you pass a closure, you could be called back on a background thread. But, if you want to do anything with the UI, that must be done on the main thread. We use DispatchQueue.main.async to pass a block to the main queue and have it run on the main thread asynchronously,
In
PHPhotoLibrary.requestAuthorization({ (newStatus) in
if newStatus == PHAuthorizationStatus.authorized {
self.showPhotoActionSheet()
}
})
You need to dispatch to the main thread
PHPhotoLibrary.requestAuthorization({ (newStatus) in
if newStatus == PHAuthorizationStatus.authorized {
DispatchQueue.main.async {
self.showPhotoActionSheet()
}
}
})
It looks like you might be calling checkPermission on the background. If so, you also need to wrap the call to:
self.showPhotoActionSheet()
From the call stack -- it looks like this might be the one you are having problems with.
I have a crash but I'm not sure what caused it.
I using Twilio framework, and all work fine, but I get a weird prod crash
I look like it a Dictionary related issue:
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000e711dbea8
Crashed: com.apple.root.background-qos
0 libobjc.A.dylib 0x182696654 object_getClass + 64
1 CoreFoundation 0x1833f3e18 _CFRelease + 1060
2 TestApp 0x100cae408 specialized _VariantDictionaryBuffer.nativeUpdateValue(_:forKey:) (TicketsManager.swift)
3 TestApp 0x100b4ba94 specialized ChatManager.getAndJoinDialog(roomId:onSuesscs:onFaild:) (ChatManager.swift:798)
4 TestApp 0x100c5e7f0 specialized ChatMessagesManager.getAllMessagesFromServerForTicket(_:) (ChatMessagesManager.swift:164)
5 TestApp 0x1009d7ca0 ChatViewController.loadAllMessagesFomServer() (ChatViewController.swift:460)
6 TestApp 0x1009feed8 partial apply for closure #1 in ChatViewController.viewWillAppear(_:) (ChatViewController.swift:234)
7 TestApp 0x100aee754 closure #1 in static Utils.performTaskOnMain(_:) (Utils.swift:84)
8 TestApp 0x1009b778c thunk for #callee_owned () -> () (QRCodeViewController.swift)
9 libdispatch.dylib 0x182dcd088 _dispatch_call_block_and_release + 24
10 libdispatch.dylib 0x182dcd048 _dispatch_client_callout + 16
11 libdispatch.dylib 0x182dda378 _dispatch_root_queue_drain + 1028
12 libdispatch.dylib 0x182dd9f10 _dispatch_worker_thread3 + 120
13 libsystem_pthread.dylib 0x183073120 _pthread_wqthread + 1268
14 libsystem_pthread.dylib 0x183072c20 start_wqthread + 4
TicketManager func:
func getAndJoinDialog(roomId : String,onSuesscs: #escaping (() -> Void),onFaild: #escaping (()-> Void)) {
if let channel = self.getDialog(roomId) {
self.addDialog(channel)
self.joinDialogWithBlock(channel, successBlock: onSuesscs, failBlock: { (_) in
onFaild()
})
return
}
self.chat?.channelsList()?.channel(withSidOrUniqueName: roomId, completion: { (result, channel) in
if result.isSuccessful() && channel != nil{
self.addDialog(channel!)
self.joinDialogWithBlock(channel!, successBlock: onSuesscs, failBlock: { (_) in
onFaild()
})
}else {
DDLogError("getAndJoinDialog error: \(String(describing: result.error))")
onFaild()
}
})
} <- **Crash on this line**
add dialog func
func addDialog(_ dialog:TCHChannel)
{
self.dialogs[dialog.sid ?? ""] = dialog
}
I'm not sure what happened that can be caused this crash
Trying to use the following piece of code to trigger email notifications for a multi-branch pipeline job:
1 def emailNotification() {
2 def to = emailextrecipients([[$class: 'CulpritsRecipientProvider'],
3 [$class: 'DevelopersRecipientProvider'],
4 [$class: 'RequesterRecipientProvider']])
5
6 //def to = "firstname.lastname#domain.com"
7 //String currentResult = currentBuild.result
8 String currentResult = manager.build.getResult()
9 echo "CurrentResult1=${currentResult}"
10 echo "CurrentResult2=${manager.build.getResult()}"
11 echo "CurrentResult3=${manager.build.result}"
12 String previousResult = currentBuild.getPreviousBuild().result
13
14 def causes = currentBuild.rawBuild.getCauses()
15 // E.g. 'started by user', 'triggered by scm change'
16 def cause = null
17 if (!causes.isEmpty()) {
18 cause = causes[0].getShortDescription()
19 }
20
21 // Ensure we don't keep a list of causes, or we get
22 // "java.io.NotSerializableException: hudson.model.Cause$UserIdCause"
23 // see http://stackoverflow.com/a/37897833/509706
25 causes = null
26
27 String subject = "${env.JOB_NAME} ${env.BUILD_NUMBER}: ${currentResult}"
28
29 String body = """
30 <p>Triggered by: <b>${cause}</b></p>
31
32 <p>Last build result: <b>${previousResult}</b></p>
33
34
35 <p>Build <b>${env.BUILD_NUMBER}</b> ran on <b>${env.NODE_NAME}</b> and terminated with <b>${currentResult}</b>.
36 </p>
37
38 <p>See: ${env.BUILD_URL}</p>
39
40 """
41
42 String log = currentBuild.rawBuild.getLog(40).join('\n')
43 if (currentBuild != 'SUCCESS') {
44 body = body + """
45 <h2>Last lines of output</h2>
46 <pre>${log}</pre>
47 """
48 }
49
50 if (to != null && !to.isEmpty()) {
51 // Email on any failures, and on first success.
52 if (currentResult != 'SUCCESS' || currentResult != previousResult) {
53 mail to: to, subject: subject, body: body, mimeType: "text/html"
54 }
55 echo 'Sent email notification'
56 }
57 }
Now, the problems that I'm facing:
def to = emailextrecipients... is not working. I found this and this Jenkins Jira issues that this may be the causes, but no workaround. Although it seems weird that if the build is started manually, say by me a user authenticated through Github Oauth, the mail can be sent. If the Github is starting the build through the webhook, I'm getting this in the Jenkins logs:
Not sending mail to user firstname.lastname#domain.com with no
permission to view
The second issue that I'm seeing is with the PostBuild email trigger.
The Pipeline looks like this:
def emailNotification() {
//the one from above
}
try {
stage('Stage1') {
/*
creating multiple nodes based on an array provided
each node will execute:
checkout scm
buildSolution() //custom method defined
*/
parallel <stuff_above>
}
stage('Stage2') {
//do other stuff
parallel <other_stuff_above>
}
} finally {
emailNotification()
}
The echoes from above (rows 9-11) are all showing null
CurrentResult1=null
CurrentResult2=null
CurrentResult3=null
Using currentBuild.currentResult will show me only SUCCESS or FAILED, but not UNSTABLE, in case some of the tests failed.
Any ideas where the problem is?
Build status is null until something sets it or until the job finishes. Are you using any unit test steps that would cause the build to be unstable?
You don't need to use emailextrecipients instead use.
emailext body: body, mimeType: 'text/html', recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']], subject: subject
Not sending mail to user firstname.lastname#domain.com with no
permission to view
Means that either no jenkins user has this email address associated or the user it is associated with does not have permission to the job
Also for causes put that logic inside a different function and add #NonCPS annotation which will stop jenkins trying to serialise state while that function is running, as you currently have it there is a small chance it will still break with that exception, see https://stackoverflow.com/a/38439681/963402
I'm having trouble with the setMaximized() method on OSX,
When I invoke it:
Scene scene = new Scene(debug);
stage.setOnCloseRequest(event -> System.exit(0));
stage.setScene(scene);
stage.setMaximized(true);
stage.show();
The app window vanishes.
For clarification I am trying to run the app from Eclipse on OSX 10.9.5.
The same logic seems to work fine on Windows.
Are there any known issues that could cause this? I don't really want to go into writing platform specific implementations of my window.
EDIT: Here is the entire class:
public class Main extends Application {
/** Pane that is used for outputting debug information about touch interactions and user interface elements. */
private DebugParent debug;
private Control customPane;
private Stage stage;
#Override
public void start(Stage stage) throws Exception {
Font.loadFont(this.getClass().getResourceAsStream("/ui/fonts/titillium.otf"), 20);
customPane = FXMLLoader.load(this.getClass().getResource("/ui/Main.fxml"), null, new CustomBuilderFactory());
customPane.dragProcessingModeProperty().set(EventProcessingMode.HANDLER);
// Init Debug
debug = new DebugParent(customPane);
debug.registerCustomPane(customPane);
debug.setOverlayVisible(false);
// Init menu
ContextMenu menu = new MainMenu(catalog, customPane);
customPane.setContextMenu(menu);
// Init scene
Scene scene = new Scene(debug);
this.stage = stage;
this.stage.setOnCloseRequest(event -> System.exit(0));
this.stage.setScene(scene);
this.stage.setMaximized(true);
this.stage.show();
this.stage.addEventHandler(KeyEvent.KEY_PRESSED, this::handleKey);
// Invalidate
customPane.invalidate();
customPane.requestFocus();
}
private void handleKey(KeyEvent keyEvent) {
switch (keyEvent.getCode()) {
case F10: stage.setMaximized(!stage.isMaximized()); break;
case F11: stage.setFullScreen(!stage.isFullScreen()); break;
}
}
public static void main(String[] args) {
launch(args);
}
}
Notably I've found that attempting to enter actual fullscreen mode from here crashes Java altogether.
2015-05-06 21:33:14.795 java[9119:507] *** Assertion failure in -[_NSWindowFullScreenTransition makeAndSetupOverlayWindow], /SourceCache/AppKit/AppKit-1265.21/AppKit.subproj/NSWindowFullScreenTransition.m:776
2015-05-06 21:33:14.799 java[9119:507] An uncaught exception was raised
2015-05-06 21:33:14.799 java[9119:507] Invalid parameter not satisfying: _transitionedWindowBeforeContents != nil
2015-05-06 21:33:14.799 java[9119:507] (
0 CoreFoundation 0x00007fff909e125c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff93d6be75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff909e1038 +[NSException raise:format:arguments:] + 104
3 Foundation 0x00007fff949f43d1 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 AppKit 0x00007fff91425068 -[_NSFullScreenTransition makeAndSetupOverlayWindow] + 267
5 AppKit 0x00007fff90e4f060 -[_NSFullScreenTransition enterFullScreenTransitionWithOptions:animated:activatingIt:] + 933
6 AppKit 0x00007fff90e4e48e -[NSWindow _enterFullScreenMode:animating:activating:] + 291
7 libglass.dylib 0x00000001204d0c99 -[GlassViewDelegate enterFullscreenWithAnimate:withKeepRatio:withHideCursor:] + 153
8 libglass.dylib 0x00000001204cc606 Java_com_sun_glass_ui_mac_MacView__1enterFullscreen + 358
9 ??? 0x0000000109281954 0x0 + 4448590164
10 ??? 0x0000000109273420 0x0 + 4448531488
11 ??? 0x0000000109273420 0x0 + 4448531488
12 ??? 0x0000000109273c4d 0x0 + 4448533581
)
2015-05-06 21:33:14.800 java[9119:507] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: _transitionedWindowBeforeContents != nil'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff909e125c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff93d6be75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff909e1038 +[NSException raise:format:arguments:] + 104
3 Foundation 0x00007fff949f43d1 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 AppKit 0x00007fff91425068 -[_NSFullScreenTransition makeAndSetupOverlayWindow] + 267
5 AppKit 0x00007fff90e4f060 -[_NSFullScreenTransition enterFullScreenTransitionWithOptions:animated:activatingIt:] + 933
6 AppKit 0x00007fff90e4e48e -[NSWindow _enterFullScreenMode:animating:activating:] + 291
7 libglass.dylib 0x00000001204d0c99 -[GlassViewDelegate enterFullscreenWithAnimate:withKeepRatio:withHideCursor:] + 153
8 libglass.dylib 0x00000001204cc606 Java_com_sun_glass_ui_mac_MacView__1enterFullscreen + 358
9 ??? 0x0000000109281954 0x0 + 4448590164
10 ??? 0x0000000109273420 0x0 + 4448531488
11 ??? 0x0000000109273420 0x0 + 4448531488
12 ??? 0x0000000109273c4d 0x0 + 4448533581
)
libc++abi.dylib: terminating with uncaught exception of type NSException
By the looks of it JavaFX is not playing nice with OSX animations.
I don't know why setMaximized() didn't work on OS X but
here are some work around that work's:
you can try to get VisualBounds width and height and use that.
Scene scene = stage.getScene();
Screen primaryScreen = Screen.getPrimary();
Rectangle2D visualBounds = primaryScreen.getVisualBounds();
double width = visualBounds.getWidth();
double height = visualBounds.getHeight();
scene = new Scene(root, width, height);
I have following code snippets where sometimes this line: self.onPostExecute(transItem) leads to application crash:
func execute(){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
//Your code to execute in background...
println("Your code to execute in background...")
var transItem:WmTransferItem = self.doInBackground()
dispatch_async(dispatch_get_main_queue(), {
println("code to be executed on the main thread when background task is finished")
self.onPostExecute(transItem) // line 639
});
});
}
What does that mean: with unmangled suffix "_promote0"
Exception:
Thread : Crashed: com.apple.main-thread
0 MyApplication 0x000e9ed8 MyApplication.WmBuildGroupsTask.onPostExecute (MyApplication.WmBuildGroupsTask)(MyApplication.WmTransferItem) -> () (WmBuildGroupsTask.swift:419)
1 libswiftCore.dylib 0x0045803b swift_reportFatalError + 162
2 MyApplication 0x000f2ddc MyApplication.WmBuildGroupsTask.(execute (MyApplication.WmBuildGroupsTask) -> () -> ()).(closure #1).(closure #1) with unmangled suffix "_promote0" (WmBuildGroupsTask.swift:639)
3 MyApplication 0x000f2e34 reabstraction thunk helper from #callee_owned () -> (#unowned ()) to #callee_unowned #objc_block () -> (#unowned ()) (WmBuildGroupsTask.swift)
4 libdispatch.dylib 0x3a133d53 _dispatch_call_block_and_release + 10
5 libdispatch.dylib 0x3a133d3f _dispatch_client_callout + 22
6 libdispatch.dylib 0x3a1366c3 _dispatch_main_queue_callback_4CF + 278
7 CoreFoundation 0x2f47a641 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
8 CoreFoundation 0x2f478f0d __CFRunLoopRun + 1308
9 CoreFoundation 0x2f3e3729 CFRunLoopRunSpecific + 524
10 CoreFoundation 0x2f3e350b CFRunLoopRunInMode + 106
11 GraphicsServices 0x343526d3 GSEventRunModal + 138
12 UIKit 0x31d44871 UIApplicationMain + 1136
13 MyApplication 0x00166417 main (main.m:32)
What I'm doing wrong?
Thanks,
I can't accept this answer as write answer but for now this example works properly and I don't have above mentioned crash in crash reports.
Here we go:
I use custom queue based on bundle name instead dispatch_get_global_queue:
let queue = dispatch_queue_create("<BUNDLE_NAME>", nil)
Example
func execute(){
let queue = dispatch_queue_create("<BUNDLE_NAME>", nil)
dispatch_async(queue, {
//Your code to execute in background...
println("Your code to execute in background...")
var transItem:WmTransferItem = self.doInBackground()
dispatch_async(dispatch_get_main_queue(), {
println("code to be executed on the main thread when background task is finished")
self.onPostExecute(transItem)
});
});
}
Hope it will help to someone.