1

backgroundSession is not working well with my app the download sometime stop and sometime done but the file saving fails

here is the code i am using just converted it today into swift but i am not sure if it's right

* AppDelegate *

var backgroundSessionCompletionHandler: ()! = Void()

    func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) {
        self.backgroundSessionCompletionHandler = completionHandler()
    }

* DownloadViewController *

func URLSessionDidFinishEventsForBackgroundURLSession(session: NSURLSession) {
        let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
        if (appDelegate.backgroundSessionCompletionHandler != nil) {
            var completionHandler:Void = appDelegate.backgroundSessionCompletionHandler
            appDelegate.backgroundSessionCompletionHandler = nil
        }
        NSLog("All backgroundSession Done")
    }

is there anything wrong with the code or is there any other useful way to do this

Amr Mohamed
  • 2,290
  • 4
  • 20
  • 39
  • Hi @Amro have you found a solution in the end? :-) – iamdavidlam Oct 21 '14 at 09:21
  • my problem was in the (didCompleteWithError) but i solved it if you need to know how to handle it? here is how : `func backgroundSession() -> NSURLSession{ var session:NSURLSession! = nil var onceToken : dispatch_once_t = 0 dispatch_once(&onceToken) { var sessionConfiguration:NSURLSessionConfiguration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("https://www.Exmaple.com") session = NSURLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil) } return session }` – Amr Mohamed Oct 21 '14 at 12:30

0 Answers0