我正在尝试处理当用户尝试在应用程序离线时上传和图像时发生的情况。有时它可以工作,Firebase 会完成并出现域错误,并且我能够创建上传任务,但是,最近,如果设备处于离线状态,则永远不会调用完成块,并且我收到 Firebase 文档中没有的日志消息。
这是上传图片的代码:
[self.storageRef child:imagePath] putData:imageData metadata:fileMeta
completion:^(FIRStorageMetadata * _Nullable metadata, NSError * _Nullable error) {
if (error) {
NSLog(@"Error uploading: %@", error);
//create local task
[self createUploadTaskForCurrentUserWithContentType:fileMeta.contentType filePath:imagePath isPhoto:NO];
return;
}
NSLog(@"Project image upload successful");
}];
这是我在重新连接互联网后收到的日志消息:
2017-03-08 15:57:27.513 TEST[15661:822730] unexpected response data (uploading to the wrong URL?)
{
"name": "-KejhLQPdFBNfyWyqCfS/1489006585133.jpg",
"bucket": "test-8822d.appspot.com",
"generation": "1489006647755852",
"metageneration": "1",
"contentType": "image/jpeg",
"timeCreated": "2017-03-08T20:57:27.683Z",
"updated": "2017-03-08T20:57:27.683Z",
"storageClass": "STANDARD",
"size": "169509",
"md5Hash": "5ZYpGG7d7jUthRIlM6yTAg==",
"contentEncoding": "identity",
"contentDisposition": "inline; filename*=utf-8''1489006585133.jpg",
"crc32c": "4+FzAg==",
"etag": "CMyIu4Lmx9ICEAE=",
"downloadTokens": "570aa9ec-d97d-4e82-8feb-c8688f9d67c8"
}
注意:在线时工作正常,唯一的问题是当我尝试离线运行代码时。