您的位置:首页 > 移动开发 > IOS开发

ios开发如何批量打包?如何让同一个程序在一个手机上多次安装时不覆盖以前安装的,而是重新生成一个新的

2012-12-21 17:45 1081 查看
Bundle identifier如果相同的话,ipa安装解压后会在同一沙盒下,出现你所说的覆盖安装。
首先,你可以在模拟器先运行一遍你的程序,在模拟器的沙盒下找的你的应用,进去找到你不想覆盖的文件及其路径。

搞清楚了以后在你的代码里找到向沙盒拷贝资源的代码,先判断文件是否存在,不存在则拷贝。

为你提供三个方法供你参考,粘贴过来格式乱了,空格你自己处理下吧。
//获取沙盒路径
-(NSString*)GetDocumentPath:(NSString*) _filename
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathstr = [paths objectAtIndex:0];
NSString *ret=[NSStringstringWithFormat:@"%@/%@",pathstr,_filename];
return ret;
}

//获取资源路径
-(NSString*)GetResPath:(NSString*) _filename Type:(NSString*) _type
{
NSString *ret = [[NSBundlemainBundle] pathForResource:_filename ofType:_type];
return ret;
}

//判断沙盒文件是否存在并拷贝
-(bool)FileExitAndCopy:(NSString*) filename FullName:(NSString*)fullfilename Type:(NSString*) _type
{
if ([[NSFileManagerdefaultManager] fileExistsAtPath:[selfGetDocumentPath:fullfilename]])
{
returntrue;
}else {
NSError *error;
NSString * tapppath = [selfGetResPath:filename Type:_type];
[[NSFileManagerdefaultManager] copyItemAtPath:tapppath toPath:[selfGetDocumentPath:fullfilename] error:&error];
if ([[NSFileManagerdefaultManager] fileExistsAtPath:[selfGetDocumentPath:fullfilename]])
{
returntrue;
}else {
returnfalse;
}
}
returnfalse;
}

本文转自http://zhidao.baidu.com/question/502866185.html

不知道有没有用,没试过
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: