Install IPA using Swift

1

I am developing a jailbreak APP , I would like to know how to install a .ipa that I downloaded from my server to install on my device (iPhone and iPad) . My application does not promote piracy, it just downloads other apps from the same developer, that is, my apps.

I was able to download the apps to the Documents folder, but I do not know what else to do with them. I have already tried to extract and paste in the Applications folder, without result. I tried to install it in the trash folder and it worked but it did not to uninstall in normal mode. Could someone help me?

Follow the code:

 import UIKit;
    import Foundation;
    class ViewController: UIViewController {
    var label : UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 400, height: 100));

    var down : Bool = false;
    var ApplicationsFolder : String = "";

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        label.text = "Nothindo to Say!";
        label.textAlignment = NSTextAlignment.Center;
        label.center = CGPointMake(100, 100);
        view.addSubview(label);
    }
    @IBAction func respring(){
        setuid(0); system("sudo reboot");
    }

    @IBAction func download(){
        if(down == false){
            var folderOrError : String = self.searchFolder();

            if(folderOrError.rangeOfString("error") == nil){
                self.down = true;
                self.ApplicationsFolder = folderOrError;

                label.text = "Baixando...";
                setuid(0);
                self.downloadPdf();

            }else{
                self.down = false;
                label.text = "Não foi possivel localizar a pasta de Applicativos!";
            }
        }
        //system("cd Applications \n ls");
    }

    func searchFolder() -> String {
        var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
        //v//ar paths = NSSearchPathForDirectoriesInDomains(folderMine, .UserDomainMask, true);
        var documentsDirectory : String;
        documentsDirectory = "/var/stash/";//paths[0] as String
        var fileManager: NSFileManager = NSFileManager()

        var fileList: NSArray = fileManager.contentsOfDirectoryAtPath(documentsDirectory, error: nil)!

        for s in fileList {

            var temp : String = s as String;
            var contenad : String = documentsDirectory+temp+"/";
            //println(contenad);
            if( contenad.rangeOfString(".lnk") == nil){
                var applicationList : NSArray = fileManager.contentsOfDirectoryAtPath(contenad, error: nil)!

                for n in applicationList {
                    var temp1 : String = n as String;
                    if(temp1.rangeOfString("Applications") != nil ){
                        return contenad+"Applications/";
                    }
                }
            }

        }


        return "error";
    }

    func fileExist(documentsDirectory : String, fileName : String) -> Bool {
        var fileManager: NSFileManager = NSFileManager()

        var fileList: NSArray = fileManager.contentsOfDirectoryAtPath(documentsDirectory, error: nil)!

        for s in fileList {

            var temp : String = s as String;

            if( temp.rangeOfString(fileName) == nil){
                return true;
            }

        }


        return false;
    }

    func saveFile(fileContent : String, file : String){
        let dirs : [String]? = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) as? [String]

        println(dirs![0]);

        if ((dirs) != nil) {
            let dir = dirs![0]; //documents directory
            let path = dir.stringByAppendingPathComponent(file);
            let text = fileContent;

            //writing
            text.writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil);

            //reading
            let text2 = String(contentsOfFile: path, encoding: NSUTF8StringEncoding, error: nil)
        }
    }

    /*func downloadPdf()
    {
        let url = NSURL(string: "http://127.0.0.1/repo/download.php")
            let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
            var returnMsg = NSString(data: data, encoding: NSUTF8StringEncoding)!;
            self.saveFile(returnMsg, file: "fileb.ipa");
        }

        task.resume()




    }*/



    func downloadPdf()
    {
        var request = NSURLRequest(URL: NSURL(string: "http://10.0.1.8/repo/PixlrExpressPlus.zip")!)
        let session = AFHTTPSessionManager()

        var progress: NSProgress?

        var downloadTask = session.downloadTaskWithRequest(request, progress: &progress, destination: {(data, responce) in self.pathUrl;
            },
            completionHandler:
            {
                response, localfile, error in
                /*println("response do download \(localfile)")

                self.label.text = "Downloaded";
                let aString: String = localfile.absoluteString!;
                let newString = aString.stringByReplacingOccurrencesOfString("file://", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil);

                let folderFile = newString.stringByReplacingOccurrencesOfString(".zip", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil);

                //system("ditto");
                //system("sudo chmod 777 \(newString)");
                //system("mkdir /var/mobile/Application/UHeuEHuHEuehuHEuHEuHEuEH");
                system("mv \(newString) /var/mobile/Application//filea.ipa")
                //system("cd Application \n ls");

                let dirs : [String]? = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) as? [String];
                let dir = dirs![0];
                SSZipArchive.unzipFileAtPath(newString, toDestination: dir);
                self.label.text = "Instalando..";
                setuid(0);
                system("chmod -R 777 \(folderFile)");
                //system("sudo mv -f \(newString) /var/mobile/Media/Downloads/myNewApp.ipa");
                system("dpkg -b \(folderFile)");
                self.label.text = "deu erro";
                //UIApplication.sharedApplication().openURL(NSURL(string: aString)!)*/
                self.label.text = "Instalando...";
                let aString: String = localfile.absoluteString!;
                let newString = aString.stringByReplacingOccurrencesOfString("file://", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil);



                let folderFile = newString.stringByReplacingOccurrencesOfString(".zip", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil);

                SSZipArchive.unzipFileAtPath(newString, toDestination: folderFile);

                let appFile = folderFile+"/PixlrExpressPlus.app";
                setuid(0);
                //println("(sudo mv -f \(appFile) \(self.ApplicationsFolder)PixlrExpressPlus.app)");
                system("sudo mv -f \(appFile) \(self.ApplicationsFolder)PixlrExpressPlus.app");
                if( self.fileExist(self.ApplicationsFolder, fileName: self.ApplicationsFolder+"PixlrExpressPlus.app")){
                    setuid(0); system("sudo chmod -R 777 \(self.ApplicationsFolder)PixlrExpressPlus.app");
                    self.label.text = "Instalado com Sucesso! Por Favor, Respringue!";
                    //system("killall SpringBoard");
                }else{
                    self.label.text = "Deu problema com o Root!";
                }

        })



        downloadTask.resume();

    }

    var pathUrl: NSURL{

        let dirs : [String]? = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) as? [String];
        let dir = dirs![0];

        let path = dir.stringByAppendingPathComponent("PixlrExpressPlus.zip");
        //let diceRoll = Int(arc4random_uniform(7));
        let url = NSURL(fileURLWithPath: path);//self.ApplicationsFolder+"temporari\(diceRoll).zip");

        return url!;
    }



    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
    
asked by anonymous 09.11.2014 / 21:40

2 answers

0

Upload through this site:

link

After uploading, click Send , then access the link that it will generate through your iPhone or iPad browser and follow the steps.

    
12.11.2014 / 11:49
0

To distribute any app outside the AppStore, you must have an Enterprise Apple Developer Enterprise Program account. Without an Enterprise account, you can only distribute an app to registered devices in your developer account.

Once you sign your app with an enterprise certificate you should follow the steps in this guide Install in-house apps wirelessly

Following these steps you will be able to install either from a web page using the safari or within an app you are developing for that purpose.

    
19.12.2017 / 13:59