我在网络连接不可用时使用plist在本地保存数据,当网络可用时,我想将本地保存的数据同步到Web服务器。如何将保存在plist中的数据与Web服务器同步?
我使用此代码。但我不知道数据是否保存在服务器中。
NSURLSessionConfiguration * configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager * manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:@"http://example url"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURL *filePath = [NSURL fileURLWithPath:@"file://my plist file"];
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromFile:filePath progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"Success: %@ %@", response, responseObject);
}
}];
[uploadTask resume];
我正在分配我的API,其中我想保存plist中的数据的URL,而我的plist在其中我的数据已经保存的文件路径。谁能解决这个问题。
你实现一个对于互联网使用连续检查甚至在后台的任何代码?首先这样做,上传是第二件事。 在这里寻找答案。 https://stackoverflow.com/questions/38691583/detecting-internet-connectivity-continually 然后在ReachableViaWWAN或ReachableViaWiFi案例中添加您在项目中使用的上传代码。 – Jamil
是的,当然我已经实现了检查网络连接的代码 –
然后通过pod包含网络连接并在网络连接文档中查找上传代码片段。用plist替换文件名。 – Jamil