पृष्ठभूमि में ऐप के दौरान कोई कार्य ट्रिगर होने पर स्थान अपडेट करें। लेकिन पृष्ठभूमि मोड के साथ एक कार्य निष्पादित करने में असमर्थ। scheduleBackgroundRefreshWithPreferredDate साथ मेरे नमूना कोडसेब iWatch पृष्ठभूमि कार्य को समय-समय पर कॉल या ट्रिगर नहीं किया जा रहा है
[WKExtension.sharedExtension scheduleBackgroundRefreshWithPreferredDate:[NSDate dateWithTimeIntervalSinceNow:60] userInfo:nil scheduledCompletion:^(NSError * _Nullable error) {
if(error == nil) {
NSLog(@"background refresh task re-scheduling successfuly ");
} else{
NSLog(@"Error occurred while re-scheduling background refresh: %@",error.localizedDescription);
}
}];
नीचे के रूप में है अनुसूची कार्य के रूप में नीचे
-(void)startLocationUpdate {
locationMgr = [[CLLocationManager alloc] init];
[locationMgr setDelegate:self];
locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
locationMgr.distanceFilter = kCLDistanceFilterNone;
// locationMgr.allowsBackgroundLocationUpdates = YES;
[locationMgr requestAlwaysAuthorization];
[locationMgr startUpdatingLocation];
[WKExtension.sharedExtension scheduleBackgroundRefreshWithPreferredDate:[NSDate dateWithTimeIntervalSinceNow:60] userInfo:nil scheduledCompletion:^(NSError * _Nullable error) {
if(error == nil) {
NSLog(@"background refresh task re-scheduling successfuly ");
} else{
NSLog(@"Error occurred while re-scheduling background refresh: %@",error.localizedDescription);
}
}];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations {
NSTimeInterval locationAge = -[[locations lastObject].timestamp timeIntervalSinceNow];
NSLog(@"Location Age : %f",locationAge);
if (locationAge > 5.0) return;
NSLog(@"latitude: %f longitude: %f",[locations lastObject].coordinate.latitude,[locations lastObject].coordinate.longitude);
//NSString *strLocation = [NSString stringWithFormat:@"%f,%f" ,[locations lastObject].coordinate.latitude , [locations lastObject].coordinate.longitude];
NSString *strLocation = @"bgLocation";
NSDictionary *applicationData = [[NSDictionary alloc] initWithObjects:@[strLocation] forKeys:@[@"watchlocation"]];
[[WCSession defaultSession] transferUserInfo:applicationData];
}
मैं iOS एप्लिकेशन को वर्तमान स्थान (अद्यतन घड़ी स्थान) भेजा करना चाहते निष्पादित नहीं किया जाना चाहिए चला जाता है, तब भी जब पृष्ठभूमि मोड – Ashish
में घड़ी एप्लिकेशन वॉचकनेक्टिविटी का उपयोग कर फोन पर आपके द्वारा स्थान की जानकारी भेजने से कोई जानकारी नहीं है। यदि आप वॉचकनेक्टिविटी का उपयोग करना चाहते हैं, तो ऐप को कम से कम फोन पर पृष्ठभूमि में चलाना होगा, इसलिए इसे घड़ी पर लाने के बजाय फोन पर स्थान डेटा प्राप्त करना और इसे आसान बनाना अधिक आसान है और इसे भेजना फ़ोन। –
यदि मुझे आईफोन पर घड़ी की स्थिति मिलती है तो मैं आईफोन और आईवॉच के बीच की दूरी की गणना करता हूं और उनके बीच की दूरी पर अधिसूचना आधार ट्रिगर करता हूं – Ashish