Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Jan 8, 2016 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 2 Apr 2012 at 12:18

@GoogleCodeExporter
Copy link
Author

are there any workarounds for this?

Original comment by [email protected] on 13 May 2012 at 5:08

@GoogleCodeExporter
Copy link
Author

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

Original comment by [email protected] on 1 Aug 2012 at 3:51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant