现在主要思路是:
实现程序A :安装到/Applications目录下,获得root权限。
A:完成的功能是:
1.下载ipa程序包。
2.检查程序是否安装,找到安装目录(已经安装)或生成新的安装目录。
3.把ipa解压,把iTurnArtwork 及.app 复制到/var/mobile/Applications/安装目录/ 下。
4.修改复制东东的权限。问题:
1.安装后要过好久桌面才会出现程序图标。(怎么程序刷新桌面或配置什么东东会让图标马上显示出来?)
2.安装后桌面的图标为白图标。(icon无效了,怎么程序处理?)
3.现在很多程序都安装在/Applications,这个是如何实现 的

解决方案 »

  1.   

    我也正在做这个东西。你拷过去试下。
    - (BOOL)InstallIPA:(NSString *)strpath
    {
    //create zip
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    NSError *error;

    ZipArchive *zip = [[ZipArchive alloc] init];
    NSString *strzippath = [strpath stringByAppendingString:@".zip"];

    if([fileMgr fileExistsAtPath:strpath])
    {
    if([fileMgr copyItemAtPath:strpath toPath:strzippath error:&error]!=YES)
    {
      NSLog(@"Unable to move file: %@", [error localizedDescription]);
      // return FALSE;
    }
    //[zip CreateZipFile2:strzippath];
    //[zip addFileToZip:strpath newname:strname];
    //[zip CloseZipFile2];
    }
    else {
    return FALSE;
    }
    //unzip
    NSString *topath = [strpath stringByDeletingPathExtension];
    if([fileMgr fileExistsAtPath:strzippath])
    {
    if([zip UnzipOpenFile:strzippath])
    {
    if([zip UnzipFileTo:topath overWrite:YES])
    {
      NSLog(@"error:");
    }
    }
    [zip UnzipCloseFile];
    }
    else {
    return FALSE;
    }
    //rename Payload and move 
    NSString *strname=[topath lastPathComponent];
    NSString *strPayload = [topath stringByAppendingString:@"/Payload"];
    NSString *syspath = [[NSString alloc] initWithString:@"/private/var/mobile/Applications/"]; 
    NSString *filename =[syspath stringByAppendingString:strname];
    if([fileMgr fileExistsAtPath:strPayload])
    {
    if([fileMgr moveItemAtPath:strPayload toPath:filename error:&error]!=YES)
    {
      NSLog(@"Unable to move file: %@", [error localizedDescription]);
    }
    NSString *strDocuments= [filename stringByAppendingString:@"/Documents"];
    [fileMgr createDirectoryAtPath:strDocuments  attributes:nil];
    }
    else 
    {
    return FALSE;
    }

    //set right
    NSDictionary *theAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:0755],NSFilePosixPermissions,nil];
     
    [fileMgr setAttributes:theAttributes ofItemAtPath:filename error:&error];
    return TRUE;
    }
      

  2.   

    您的这个代码与我的差不多?
    我的问题是:
    1.安装后要过好久桌面才会出现程序图标。(怎么程序刷新桌面或配置什么东东会让图标马上显示出来?)
    2.安装后桌面的图标为白图标。(icon无效了,怎么程序处理?)
    3.现在很多程序都安装在/Applications,这个是如何实现 的
      

  3.   

    我的代理 #pragma  -
    #pragma  第一步下载
    -(void)downLoad{
    [self addText:@"开始下载!!!"];
    [CAsynchHttpNew createAsynchHttp:DOWN_LOAD_HTTP andDelegate:self];
    }#pragma  -
    #pragma  第二步解压
    -(void)installIpa{
    [self addText:@"开始解压!!!"];
    NSString *sToFullPath = [CFunc getSaveZipPath:APP_FILE_NAME];
    [CZip unpackZip:FILE_NAME toFullPath:sToFullPath];
    [self addText:@"解压完成!!!"];
    [self copyFileAndChangeMod];
    }//复制文件
    -(void)copyFiles:(NSString *)sToPath{
    NSString *sFromCopyFile = [CFunc getSaveZipPath:APP_FILE_NAME];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error = nil;
    //复制iTunesArtwork;
    NSString *sItunesArtworkPath = [NSString stringWithFormat:@"%@/iTunesArtwork",sFromCopyFile];
    NSString *sToItunesArtworkPath = [NSString stringWithFormat:@"%@/iTunesArtwork",sToPath];
    if ([fileManager fileExistsAtPath:sToItunesArtworkPath]) {
    [fileManager removeItemAtPath:sToItunesArtworkPath error:NULL];
    }
    if (![fileManager copyItemAtPath:sItunesArtworkPath toPath:sToItunesArtworkPath error:&error]) {
    NSLog(@"Error:%@",[error description]);
    }

    //复制app
    NSString *sAppPath = [NSString stringWithFormat:@"%@/Payload/DuoYiIM.app",sFromCopyFile];
    NSString *sToAppPath = [NSString stringWithFormat:@"%@/DuoYiIM.app",sToPath];
    if ([fileManager fileExistsAtPath:sToAppPath]) {
    [fileManager removeItemAtPath:sToAppPath error:NULL];
    }
    if (![fileManager copyItemAtPath:sAppPath toPath:sToAppPath error:&error]) {
    NSLog(@"Error:%@",[error description]);
    }
    }//改变权限
    -(void)changeMod:(NSString *)sToPath{
    NSNumber *iTunesArtworkFilePower = [NSNumber numberWithInteger:0644];
    NSString *sItunesArtworkPath = [NSString stringWithFormat:@"%@/iTunesArtwork",sToPath];
    [CFunc changeFilePower:sItunesArtworkPath andPower:iTunesArtworkFilePower];
    NSNumber *filePower = [NSNumber numberWithInteger:0755];
    NSString *sAppPath = [NSString stringWithFormat:@"%@/DuoYiIM.app",sToPath];
    [CFunc changeFilePathPower:sAppPath andPower:filePower];
    }#pragma  -
    #pragma  第三步安装
    -(void)copyFileAndChangeMod{
    [self addText:@"开始检测安装!!!"];
    NSString *sInstallPath = [CFunc getInstallFullPath:INSTALL_PATH andAppName:APP_FILE_NAME]; //[CFunc getZipFullPath:INSTALL_PATH2]
    [self addText:@"开始复制文件!!!"];
    [self copyFiles:sInstallPath];
    [self addText:@"开始修改权限!!!"];
    [self changeMod:sInstallPath];
    [self addText:@"检查复制及修改文件完成!!!"];
    [self clearData];
    }#pragma  -
    #pragma  第四步清理数据
    -(void)clearData{
    [self addText:@"清理数据开始!!!"];
    NSString *sZipPath = [CFunc getZipFullPath:FILE_NAME];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:sZipPath error:NULL];

    NSString *sExpandZipPath = [CFunc getZipFullPath:APP_FILE_NAME];
    [fileManager removeItemAtPath:sExpandZipPath error:NULL];
    [self addText:@"清理数据完成!!!"];
    [self addText:@"安装完成!!!"];
    }
      

  4.   


    //解压zip 
    +(void)unpackZip:(NSString *)sSubPath toFullPath:(NSString*)sFullPath{
    ZipArchive* zip = [[ZipArchive alloc] init];
    NSString *zipFullPath = [CFunc getZipFullPath:sSubPath];
    if( [zip UnzipOpenFile:zipFullPath] )
    {
    BOOL ret = [zip UnzipFileTo:sFullPath overWrite:YES];
    if( NO==ret )
    {
    NSLog(@"zip error %d",ret);
    }
    [zip UnzipCloseFile];
    }
    NSLog(@"unpack Zip OK");
    [zip release];
    }
    @end
      

  5.   

    继续求解:
    1.安装后要过好久桌面才会出现程序图标。(怎么程序刷新桌面或配置什么东东会让图标马上显示出来?)
    2.安装后桌面的图标为白图标。(icon无效了,怎么程序处理?)
      

  6.   

    如果图标很久出来,那么你得强制respring了或者重启机器了,这没办法的。
      

  7.   

    关键是这个程序没有权限是创建目录什么的。例如:/private/var/mobile/Applications/ 创建沙河目录,老是失败,操作不允许,权限怎么解决?