, iOS 8. DidDismissOpenInMenu , , . , , , . , , ; -, , , .
, , , DocumentInteractionController, , , :
- (void)openIn:(NSData *)fileData {
NSString *fileName = [NSString stringWithFormat:@"%@.pdf", self.name];
NSString *filePath = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(), fileName];
BOOL result = [fileData writeToFile:filePath atomically:TRUE];
if (result) {
self.sendingFile = FALSE;
NSURL *URL = [NSURL fileURLWithPath:filePath];
UIDocumentInteractionController *controller = [[UIDocumentInteractionController interactionControllerWithURL:URL] retain];
controller.delegate = self;
[controller presentOpenInMenuFromBarButtonItem:self.openInButton animated:TRUE];
}
}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
self.sendingFile = TRUE;
}
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
if (!self.sendingFile) {
[self openInCleanup];
}
}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application {
[self openInCleanup];
self.sendingFile = FALSE;
}
- (void)openInCleanup {
NSString *fileName = [NSString stringWithFormat:@"%@.pdf", self.name];
NSString *filePath = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(), fileName];
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
}
iOS 11
iOS 11 , , , - , , . iOS 11 , - , . Documents openInCleanup , tmp tmp . iOS. openInCleanup, tmp applicationDidFinishLaunching:
NSString *tmpDirectory = [NSString stringWithFormat:@"%@/tmp", NSHomeDirectory()];
NSArray *tmpFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tmpDirectory error:NULL];
for (NSString *tmpFile in tmpFiles) {
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", tmpDirectory, tmpFile] error:NULL];
}