gpt4 book ai didi

cocoa - 将捆绑的应用程序发送到“应用程序”文件夹

转载 作者:行者123 更新时间:2023-12-03 17:29:42 25 4
gpt4 key购买 nike

我正在尝试将项目包中的应用程序移动到用户的“应用程序”文件夹中。捆绑的“testApp.app”位于项目的 Resources 文件夹中。我的代码没有完成它。我指向用户系统上的全局应用程序文件夹的方式是否有问题?

谢谢。

保罗

NSFileManager* fileManager = [NSFileManager defaultManager];

NSError *error = nil;

NSString *appDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString *path = [appDirectory stringByAppendingPathComponent:@"~/Applications/testApp.app"];
[path stringByExpandingTildeInPath];


if ([fileManager fileExistsAtPath:path isDirectory:NULL]) {
[fileManager removeItemAtPath:path error:&error];

}

if(![fileManager fileExistsAtPath:path]){
}


NSData *data = [NSData dataWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/testApp.app"]];
[data writeToFile:path atomically:YES];

最佳答案

.app"file"实际上不是文件,它们是目录(右键单击其中一个并“显示内容”)。因此,您需要照此复制它们。

您的代码还存在一些其他问题,[NSString stringBy...] 消息返回一个 字符串,因为 NSString 是不可变的,因此您需要分配返回值,而不仅仅是传递消息。

关于cocoa - 将捆绑的应用程序发送到“应用程序”文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6416091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com