Install IPA using Swift

Asked

Viewed 412 times

1

I’m developing an APP for jailbreak, I would like to know how to install a .ipa that I downloaded from my server to be able to install on the device (iPhone and iPad). My app does not promote piracy, only downloads other apps from the same developer, ie my apps.

I was able to download the apps to the folder Documents, but I don’t know what else to do with them. I’ve tried to extract and paste into the folder Applications, no result. I tried to install in the Trash folder and it worked but not to uninstall in normal mode. Someone could help me?

Follows 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.
    }

}

2 answers

0

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

After signing your app with an Enterprise certificate you should follow the steps found in this guide Install in-house apps Wirelessly

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

0

Upload via this site:

http://www.diawi.com/

After the upload click on Send, after that access the link that it will generate through the browser of your iPhone or iPad and follow the steps.

  • My purpose would be to install the app via my app not with an external website as it is already possible to install using third-party software like ifunbox.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.