Skip to content

Commit 5e8654a

Browse files
committed
fix iOS download file.bin alert
1 parent 4e25e17 commit 5e8654a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

apple/RNCWebViewImpl.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,20 @@ -(void)setKeyboardDisplayRequiresUserAction:(BOOL)keyboardDisplayRequiresUserAct
973973
}
974974

975975
- (void)downloadBase64File:(NSString *)base64String {
976+
// Infer file extension from the data: URL before doing any heavy work.
977+
// For generic application/octet-stream payloads we suppress the download
978+
// entirely (no "Do you want to download File.bin?" alert), since these
979+
// are typically iframe-driven noise rather than user‑initiated downloads.
980+
NSString *fileExtension = [self fileExtensionFromBase64String:base64String];
981+
if ([[fileExtension lowercaseString] isEqualToString:@"bin"]) {
982+
NSLog(@"RNCWebViewImpl: Ignoring generic binary download (File.bin) from data: URL");
983+
return;
984+
}
985+
976986
NSArray *components = [base64String componentsSeparatedByString:@","];
977987
NSString *base64ContentPart = components.lastObject;
978988

979989
NSData *fileData = [[NSData alloc] initWithBase64EncodedString:base64ContentPart options:NSDataBase64DecodingIgnoreUnknownCharacters];
980-
NSString *fileExtension = [self fileExtensionFromBase64String:base64String];
981990
[self showDownloadAlert:fileExtension invokeDownload:^{
982991
NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"File.%@", fileExtension]];
983992
[fileData writeToFile:tempFilePath atomically:YES];

0 commit comments

Comments
 (0)