आप पृष्ठभूमि कार्य एपीआई के बाद आप backgrounded किया गया है (जब तक उपयोग कर सकते हैं एक विधि कॉल करने के रूप में अपने काम के लिए नहीं ले करता है बहुत लंबा - आमतौर पर ~ 10 मिनट अधिकतम अनुमत समय है)।
आईओएस पृष्ठभूमि के समय टाइमर आग नहीं देता है, इसलिए मुझे पता चला है कि ऐप पृष्ठभूमि से पहले पृष्ठभूमि थ्रेड भेज रहा है, फिर उस थ्रेड को सोने के लिए डालने पर, टाइमर के समान प्रभाव पड़ता है।
अपने अनुप्रयोग प्रतिनिधि के - (void)applicationWillResignActive:(UIApplication *)application
विधि में निम्नलिखित कोड डालें:
// Dispatch to a background queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// Tell the system that you want to start a background task
UIBackgroundTaskIdentifier taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
// Cleanup before system kills the app
}];
// Sleep the block for 5 seconds
[NSThread sleepForTimeInterval:5.0];
// Call the method if the app is backgrounded (and not just inactive)
if (application.applicationState == UIApplicationStateBackground)
[self performSelector:@selector(test)]; // Or, you could just call [self test]; here
// Tell the system that the task has ended.
if (taskID != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:taskID];
}
});
स्रोत
2013-07-11 10:48:01
** AppDelegate.m फ़ाइल में अपने तरीके ** 'applicationWillResignActive' और उसके बाद' applicationDidEnterBackground' कहा जाता है। – Rohan
धन्यवाद। लेकिन मेरा मतलब है, जब यह पृष्ठभूमि में है – Rubinc
पर एक नज़र डालें [मैं आईफोन होम स्क्रीन प्रोग्रामशैली के स्क्रीनशॉट कैसे ले सकता हूं] (http://stackoverflow.com/q/13459682/593709) –