ios - How to implement a background process using parse -


I am developing an iphone application for referrals. It uses pars to retain users, contacts and referrals. It also uses core data to synchronize with pars and to maintain offline activities. There is a refresh method that synchronizes pars with core data. I am trying to find a way that as soon as the user leaves the app, synchronization with pars is done in the background. I'm testing using a simple parse query in ApplicationDidEnterBackground but it is not working. Here is the code I used:

  (zero) applicationDidEnterBackground: (UIApplication *) application {self.backgroundTask = [application beginBackgroundTaskWithName: @ "MyTask" expirationHandler: ^ {[application endBackgroundTask: self . background task]; Self.backgroundTask = UIBackgroundTaskInvalid; }]; Dispatch_asink (Dispatches_Get_Global_Qu (Dispatch_QUPRIIfFLT, 0), ^ {NSSTING * Message @ "Start Background Background"; NSDictionary * dict = @ {@ "Status": Message}; [[NSUser Defaults Standard User Defaults] Set Object: Dict My To: KBHighbackHouseTaskwithNameKey]; PFQL * query = [PFQuery queryWithClassName: @ "referral"]; [query findObjectsInBackgroundWithBlock: ^ (NSArray * objects, NSError * error) {if (! Error) {NSString * message = [ NSString stringWithFormat: @ "array is% objects", (objects unsigned long) objects.count]; NSDictionary * dict = @ {@ "status": message}; [[NSUserDefaults standardUserDefaults] setObject: dict forKey: kBeginBackgroundTaskWithNameKey]; [Applications EndBackgroundTask: self.backgroundTask]; self.backgroundTask = UIBackgroundTaskInvalid;}}};}); }  

What am I doing wrong?

After

I finally found a way to solve my problem, for the guidance I used to refer to Ray Wendrelich's tutorial" IOS Background mode "used here Main changes in AppDelegate:

- (zero) parseSync {

  sender_accommon (sender_gate_global_que (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {// parse Code ....}); Self.backgroundTask = Start [[UIApplication SharePractical] BackgroupSavewithExceptionHandler: ^ {NSLog (@ "Background handler called. Now no background work is going on."); [[UIApplication ShareApp] Endbacker Task: self.backgroundTask]; Self.backgroundTask = UIBackgroundTaskInvalid; }]; (Zero) application WillResignActive: (UIApplication *) application { 

[self parseSync];

P>

}


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -