NSDocumentsDirectory更改

时间:2019-07-05 17:33:05

标签: xcode nsdocument

我有一个将UIImage保存到NSDocumentsDirectory中的路径的代码。然后,我调用路径并将图像发送到电子邮件。它工作正常,但是当我退出应用程序并重新启动它时,如果我尝试重新发送图像,则应用程序将崩溃。它正在尝试访问我假设的先前目录。我想我想做的就是将UIImage保存到以后可以检索的路径。

这是保存代码。

-(IBAction)savefile (id)sender
{

 Uppaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        documentsDirectory = [Uppaths objectAtIndex:0];
        NSString * prefixString = self.record.eventname;

        NSString * guid = [self randomStringWithLength:6];
        NSString * uniqueFileName = [NSString stringWithFormat:@"%@_%@.jpg", prefixString, guid];
        _imagePathLayout = [documentsDirectory stringByAppendingPathComponent:uniqueFileName];
        NSData *data1 = UIImageJPEGRepresentation(newImage, _photoquality);
        [data1 writeToFile:_imagePathLayout atomically:YES];

        NSLog(@"filepath=%@", _imagePathLayout);
        refURLLayout = [NSURL fileURLWithPath:_imagePathLayout];
        [self.storeLayout addObject:_imagePathLayout];


}

这是上传代码。只要我不退出应用程序,它就可以正常工作。

-(void)sendUploadPathMulti:(NSString *)path imageArray:(NSMutableArray *)imageArray subjectstring:(NSString *)subject messagestring:(NSString *)message filename:(NSString *)filename linkurl:(NSURL *)linkurl linkstring:(NSString *)linkstring deleteItem:(NSString *)deleteitem

{

for (int i = 0; i < imageArray.count; i++) {

        NSString *path = [imageArray objectAtIndex:i];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:path];
        NSData *data = [[NSFileManager defaultManager] contentsAtPath:folderPath];
        NSString * prefixString = self.record.eventname;
        NSString * uuidString = [self randomStringWithLength:4];
        NSString *uuid = [NSString stringWithFormat:@"%@",uuidString];
        NSString *final = [NSString stringWithFormat:@"%@_%@.jpg", prefixString, uuid];

        NSLog (@"path: %@", path);

        MCOAttachment *attachment = [MCOAttachment attachmentWithData:data filename:final];
        [builder addAttachment:attachment];
        NSLog (@"ATTACH1: %@", attachment);
    }

}

这是错误。无法读取文件://://var/mobile/Containers/Data/Application/80A36161-2815-480D-A9BB-A4766E0DD39A/Documents/test_KgUpp0.jpg

0 个答案:

没有答案