मैं this post में दिए गए सुझावों को लागू करने का प्रयास कर रहा हूं।ऐप पृष्ठभूमि पर जाने के बाद प्रत्येक एन मिनट में उपयोगकर्ता स्थान प्राप्त करना
दुर्भाग्य से मेरे लिए कदम स्पष्ट नहीं हैं। मैंने उन सुझावों को लागू करने का प्रयास किया, लेकिन पृष्ठभूमि सेवा शुरू करने और रोकने के बाद भी पृष्ठभूमि टाइममेमिंग में कमी आई है। यह मैं इसे कैसे विकसित है:
- (void)applicationDidEnterBackground:(UIApplication *)application {
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
self.timer = nil;
[self initTimer];
});
}
initTimer:
- (void)initTimer {
// Create the location manager if this object does not
// already have one.
if (nil == self.locationManager)
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startMonitoringSignificantLocationChanges];
if (self.timer == nil) {
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.3
target:self
selector:@selector(checkUpdates:)
userInfo:nil
repeats:YES];
}
}
checkUpdates:
- (void)checkUpdates:(NSTimer *)timer{
UIApplication* app = [UIApplication sharedApplication];
double remaining = app.backgroundTimeRemaining;
if(remaining < 580.0) {
[self.locationManager startUpdatingLocation];
[self.locationManager stopUpdatingLocation];
[self.locationManager startMonitoringSignificantLocationChanges];
}
DbgLog(@"Reminaing %f", app.backgroundTimeRemaining);
}
किसी को क्या मेरी कोड में गलत हो सकता है पर एक सुझाव है? InitTimer और checkUpdates दोनों को बुलाया जा रहा है, लेकिन केवल पृष्ठभूमि निष्पादन समय (+ - 10 मिनट) के दौरान। मैं ऐप को "हमेशा के लिए" हर एन मिनट में स्थान अपडेट करना चाहता हूं।
मेरे ऐप का UIBackgroundModes स्थान पर सेट है।
अद्यतन:
मैं अब didUpdateToLocation और didFailWithError पर टाइमर को रीसेट कर रहा हूँ। लेकिन फिर भी backgroundTimeRemaining कम हो रही रखता है:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(@"Did Update Location = %f/%f", [newLocation coordinate].latitude, [newLocation coordinate].longitude);
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
[self initTimer];
});
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
[self.locationManager stopUpdatingLocation];
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
[self initTimer];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
});
}
मैं भी टाइमर अमान्य कर रहा हूँ:
- (void)checkUpdates:(NSTimer *)timer{
UIApplication* app = [UIApplication sharedApplication];
double remaining = app.backgroundTimeRemaining;
if(remaining < 580.0 && remaining > 570.0) {
[self.timer invalidate];
self.timer = nil;
[self.locationManager startUpdatingLocation];
[self.locationManager stopUpdatingLocation];
}
DbgLog(@"*************************Checking for updates!!!!!!!!!!! Reminaing %f", app.backgroundTimeRemaining);
}
क्या आपका ऐप ऐप स्टोर में स्वीकार किया गया है? मैं एक ही दृष्टिकोण लेने पर विचार कर रहा हूं लेकिन मुझे यह सुनिश्चित करने की ज़रूरत है कि मेरा ऐप खारिज नहीं किया जाएगा। धन्यवाद बीटीडब्ल्यू! – aslisabanci
क्या आपको यह काम करने के लिए मिला? –