vaghanirahul / skpsmtpmessage

Automatically exported from code.google.com/p/skpsmtpmessage
0 stars 0 forks source link

Library doesn't appear to work when executed as background task #57

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run your send mail function inside a background task code block e.g.

{{{
- (void) sendMessageInBackground
{
    UIApplication* application = [UIApplication sharedApplication];
    bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
        // Clean up any unfinished task business by marking where you.
        // stopped or ending the task outright.

        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    // Start the long-running task and return immediately.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        [self sendMessageDirectly]; 

        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    });

}
}}}

What is the expected output? What do you see instead?

The same function called directly will successfully send an email. When the 
same function is called from inside an execution block it doesn't return 
successfully. The last log output is:

2012-04-02 13:10:11.146 Test Project[1954:3203] C: Attempting to connect to 
server at: smtp.gmail.com:25

What version of the product are you using? On what operating system?
I'm using Xcode 4.3.2, lion and iOS 5.1

Original issue reported on code.google.com by mushroom...@googlemail.com on 2 Apr 2012 at 12:18

GoogleCodeExporter commented 9 years ago
are there any workarounds for this?

Original comment by g...@jga23.com on 13 May 2012 at 5:08

GoogleCodeExporter commented 9 years ago
One workaround is to make a selector for sending and call 
performSelectorOnMainThread. I can confirm that working from within block.

Original comment by dunja.la...@dlmprojekt.com on 1 Aug 2012 at 3:51