我在下面的代码部分中使用saveEventually
。问题是,只有当应用程序完全关闭并重新打开时,应用程序最小化并重新打开时,saveEventually不起作用。有没有办法抵消这个?
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// Generate Random Number
int random = arc4random_uniform(1000000000);
// Updates Location
NSLog(@"Location: %@",newLocation);
CLLocation *curentLocation = newLocation;
if (curentLocation != nil) {
// Submit through Parse
PFObject *object = [PFObject objectWithClassName:@"Issue"];
object[@"ID"] = [NSString stringWithFormat:@"%i",random];
object[@"Latitude"] = [NSString stringWithFormat:@"%.8f",curentLocation.coordinate.latitude];
object[@"Longitude"] = [NSString stringWithFormat:@"%.8f",curentLocation.coordinate.longitude];
object[@"Signal"] = [NSString stringWithFormat:@"%@",_avgNumber];
[object saveEventually];
// Update Text Fields
self.latitude.text = [NSString stringWithFormat:@"%.8f",curentLocation.coordinate.latitude];
self.longitude.text = [NSString stringWithFormat:@"%.8f",curentLocation.coordinate.longitude];
self.signal.text = [NSString stringWithFormat:@"%@",_avgNumber];
}
// Stop the Location Update
[manager stopUpdatingLocation];
}
答案 0 :(得分:1)
saveEventually
将在您描述的两种情况下发挥作用。从Parse开始:“使用此方法保存的对象将本地存储在磁盘缓存中,直到它们可以传递给Parse。
如果可能,会立即发送。否则,它们将在下次有网络连接时发送。“
它应该可以工作,但作为临时解决方法,如果不是,您可以在保存对象之前检查连接。如果您有互联网连接,请使用saveInBackground
,否则请使用saveEventually
。所以像这样:
if (isNetworkAvailable)
[object saveInBackground];
else
[object saveEventually];
- (BOOL)isNetworkAvailable
{
CFNetDiagnosticRef dReference;
dReference = CFNetDiagnosticCreateWithURL (NULL, (__bridge CFURLRef)[NSURL URLWithString:@"www.apple.com"]);
CFNetDiagnosticStatus status;
status = CFNetDiagnosticCopyNetworkStatusPassively (dReference, NULL);
CFRelease (dReference);
if ( status == kCFNetDiagnosticConnectionUp )
{
NSLog (@"Connection is Available");
return YES;
}
else
{
NSLog (@"Connection is down");
return NO;
}
}