gpt4 book ai didi

ios - saveEventually - 在使用 Parse 最小化应用程序时保存

转载 作者:行者123 更新时间:2023-11-29 12:39:06 34 4
gpt4 key购买 nike

我在下面的代码部分使用了 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];

}

最佳答案

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;
}
}

关于ios - saveEventually - 在使用 Parse 最小化应用程序时保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25506494/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com