同步操作将从 hackcat/react-native-code-push 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#import "CodePush.h"@implementation CodePushDownloadHandler {// Header chars used to determine if the file is a zip.char _header[4];}- (id)init:(NSString *)downloadFilePathoperationQueue:(dispatch_queue_t)operationQueueprogressCallback:(void (^)(long long, long long))progressCallbackdoneCallback:(void (^)(BOOL))doneCallbackfailCallback:(void (^)(NSError *err))failCallback {self.outputFileStream = [NSOutputStream outputStreamToFileAtPath:downloadFilePathappend:NO];self.receivedContentLength = 0;self.operationQueue = operationQueue;self.progressCallback = progressCallback;self.doneCallback = doneCallback;self.failCallback = failCallback;return self;}- (void)download:(NSString *)url {self.downloadUrl = url;NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]cachePolicy:NSURLRequestUseProtocolCachePolicytimeoutInterval:60.0];NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:requestdelegate:selfstartImmediately:NO];if ([NSOperationQueue instancesRespondToSelector:@selector(setUnderlyingQueue:)]) {NSOperationQueue *delegateQueue = [NSOperationQueue new];delegateQueue.underlyingQueue = self.operationQueue;[connection setDelegateQueue:delegateQueue];} else {[connection scheduleInRunLoop:[NSRunLoop mainRunLoop]forMode:NSDefaultRunLoopMode];}[connection start];}#pragma mark NSURLConnection Delegate Methods- (NSCachedURLResponse *)connection:(NSURLConnection *)connectionwillCacheResponse:(NSCachedURLResponse*)cachedResponse {// Return nil to indicate not necessary to store a cached response for this connectionreturn nil;}- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {if ([response isKindOfClass:[NSHTTPURLResponse class]]) {NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];if (statusCode >= 400) {[self.outputFileStream close];[connection cancel];NSError *err = [CodePushErrorUtils errorWithMessage:[NSString stringWithFormat: @"Received %ld response from %@", (long)statusCode, self.downloadUrl]];self.failCallback(err);return;}}self.expectedContentLength = response.expectedContentLength;[self.outputFileStream open];}- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {if (self.receivedContentLength < 4) {for (int i = 0; i < [data length]; i++) {int headerOffset = (int)self.receivedContentLength + i;if (headerOffset >= 4) {break;}const char *bytes = [data bytes];_header[headerOffset] = bytes[i];}}self.receivedContentLength = self.receivedContentLength + [data length];NSInteger bytesLeft = [data length];do {NSInteger bytesWritten = [self.outputFileStream write:[data bytes]maxLength:bytesLeft];if (bytesWritten == -1) {break;}bytesLeft -= bytesWritten;} while (bytesLeft > 0);self.progressCallback(self.expectedContentLength, self.receivedContentLength);// bytesLeft should not be negative.assert(bytesLeft >= 0);if (bytesLeft) {[self.outputFileStream close];[connection cancel];self.failCallback([self.outputFileStream streamError]);}}- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error{[self.outputFileStream close];self.failCallback(error);}- (void)connectionDidFinishLoading:(NSURLConnection *)connection {[self.outputFileStream close];if (self.receivedContentLength < 1) {NSError *err = [CodePushErrorUtils errorWithMessage:[NSString stringWithFormat:@"Received empty response from %@", self.downloadUrl]];self.failCallback(err);return;}// expectedContentLength might be -1 when NSURLConnection don't know the length(e.g. response encode with gzip)if (self.expectedContentLength > 0) {// We should have received all of the bytes if this is called.assert(self.receivedContentLength == self.expectedContentLength);}BOOL isZip = _header[0] == 'P' && _header[1] == 'K' && _header[2] == 3 && _header[3] == 4;self.doneCallback(isZip);}@end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。