How can I use a progress bar in objective c mac

How can I use a progress bar in objective c mac? I have a code that downloads a file and I want to be able to let the progress bar increase by 1. A bit further on the code (to download the file) it needs to increase again. And so on...
My code
-(IBAction) downloadButtonPressed:(id)sender;{
    //get the path to the image that we're going to download
    NSURL *url = [NSURL URLWithString:@"https://www.dropbox.com/s/l6o07m48npxknt4/Cluedo.zip?dl=1"];
    //get the path to documents folder where we're going to save our image
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *DocumentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [DocumentsDirectory stringByAppendingPathComponent:@"Cluedo.zip"];
    //Download the file to memory
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSError *error = nil;
    //Save it on the Documents directory
    [data writeToFile:filePath options:NSDataWritingAtomic error:&error];
    NSFileManager* fm = [NSFileManager defaultManager];
    NSString* zipPath = filePath;
    NSString* targetFolder = @"/Applications"; //this it the parent folder
    //where your zip's content
    //goes to (must exist)
    //create a new empty folder (unzipping will fail if any
    //of the payload files already exist at the target location)
    [fm createDirectoryAtPath:targetFolder withIntermediateDirectories:NO
                   attributes:nil error:NULL];
    //now create a unzip-task
    NSArray *arguments = [NSArray arrayWithObject:zipPath];
    NSTask *unzipTask = [[NSTask alloc] init];
    [unzipTask setLaunchPath:@"/usr/bin/unzip"];
    [unzipTask setCurrentDirectoryPath:targetFolder];
    [unzipTask setArguments:arguments];
    [unzipTask launch];
    //[unzipTask waitUntilExit]; //remove this to start the task concurrently

Your code really isn't suitable for a progress bar, not a real one anyway. Your code will spend about 99.9% of its time in the method "dataWithContentsOfURL:url". That is not a method you want to use in the real world. It is only for demos or proof of concept exercises. All network operations should be asynchronous. That gives you the ability to gracefully recover when there is a failure and also to do fancy things like display a progress bar and tell the user when the download is complete.
Once you get the asynchronous download logic working, then you can worry about the progress bar. The first thing you will need is the size of the file. Without that, all you can ever do is an indeterminate progress bar or spinner. If you have the size of the file, then you can keep track of how much of the file you have downloaded and update your progress bar with the percentage complete. Make sure to throttle it to no more than incrementing by 1% at a time. Otherwise, a large file or a file transferred in many small chunks, would waste too much time updating the progress bar for no change.

Similar Messages

  • How can I add a Progress bar to show the "render to JPG" progress?

    Hi everyone, I have a button which renders my component to
    JPG.
    How can I attach a progress bar to show the progress of the
    rendering?
    <mx:Button label="render" click="renderasJPEG ()"/>
    public function renderasJPEG( ):void
    convertToImage( component001, new JPEGEncoder( 100));
    private function convertToImage( object:IUICompon ent,
    encoder:IImageEncod er):void
    var base64string: String = ImageSnapshot. encodeImageAsBas
    e64(
    ImageSnapshot. captureImage( object, 72, encoder));
    var variables:URLVariab les = new URLVariables( );
    variables.encoded = base64string;
    variables.type = "jpeg";
    var request:URLRequest = new URLRequest(" script_saveasima
    ge.php");
    request.method = "POST";
    request.data = variables;
    navigateToURL( request, "_blank");
    Thanks in advance.

    Hi,
    I would have thrown a prompt to the user in the renderasJpeg
    function and removed it in last line of convertToImage function.
    Isn't this what you want?
    Hope this helps.

  • I want to hook up a mac mini and us my tv as a monitor. how can I use airplay from my phone on the mac mini like i can with an apple tv (without having to buy an apple tv!). the airplay capabilities i want to use are mirroring and streaming from my iphone

    i want to hook up a mac mini and us my tv as a monitor. how can I use airplay from my phone on the mac mini like i can with an apple tv (without having to buy an apple tv!). the airplay capabilities i want to use are mirroring and streaming from my iphone!

    Download AirPlayer for Mac - Transforms your Mac into an AirPlay-compatible display. MacUpdate.com

  • HT4614 How can i use the Thunderbolt cable to link my Mac computers

    How can i use the Thunderbolt cable to link my Mac computers

    Connect them with it and start up one computer with the T key held down.
    (76624)

  • How can I use my iphone as modem for my mac?

    How Can I use my iphone 4 as modem for my mac-pro in areas where there is not Wi-Fi

    If your cell phone carrier supports tethering with the iPhone, you need to sign up for a tethering plan with your carrier first.
    http://support.apple.com/kb/HT3574

  • How can i Create a PROGRESSIVE BAR   while process of a procedure is going

    hi,
    I have a push button in my form that runs the procedure .the process will approx 15 minutes. while processing is started, i want to display PROGRESSIVE BAR
    until process complete and exits automatically after process . please suggest me how to create the same, is it possible..
    please send me solution as soon as possible please
    thanks in advance
    prasanth

    The forms demos contains a progress bar bean which you can use if web deployed.
    Regards
    Grant Ronald
    Forms Product Management

  • How to make use of *progress bar*?

    I have a progress bar requirement in my swings project,
    i.e on clicking a button, some task should be executed and in parallel to this
    progress should run on progress bar in the same frame and soon after this task
    gets completed the progress on progress bar should come to an end.
    How can i do this in swings?
    could any one help me out from this?

    How to use progress bar
    http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
    If you want an example scroll down to the bottom of the page and download the examples.

  • How can i add a progress bar to my UIwebview

    i have a page in my application where i have a UIWebview what i want to do is have a progress bar somewhere on the screen to indicate the loading status on the page.

    Go to your xib file or storyboard file, then you should see Progress view in the objects.

  • How can I use the same catalog on PC and MAC?

    I keep my catalog and photos on an external hard drive.  I have both PCs and a MAC and I would like to be able to access the same catalog of photos on both my PC and my MAC using LR2.  I am using v 2.3.  The problem is the location of the photo is referenced differently on the PC than on the MAC.  Does any one have any idea how I might accomplish this?
    If this is impossible, then can anyone at least tell me how I can convert my catalog file (lrcat) so that the location of photos that are currently referenced using a drive and path (eg, p:\myphotos\...) to a format that can be used on the MAC so Lightroom running on the MAC will know about the photos on my external drive?

    I have figured out the answer to my question.  Thanks to those who tried to help.
    First of all, I found that Lightroom's 'Locate folder' didn't work for me.  It might have if I had tried that the first time I tried to convert things, but I had tried to locate a few photos already, so I was always told that the folder I was trying to locate was already in the catalog.
    Breifly, what did work was to locate individual photos using the ? you see on the photo when in grid mode in the Library view and specify that other photos nearby should also be relocated.  By choosing a photo at the top of the directory tree, Lightroom will search for all photos in the directory containing your photo and all subdirectories of it.
    The details:
    What did work, was to individually locate photos using the ? you see on the photo when in grid mode in the Library view.  If you turn on the choice to locate other photos nearby, then Lightroom will search for other photos in this directory and in all subdirectories of the one containing your located photo.  This was a good start, but the problem for me is that my photos are stored in many directories below an organizing directory (eg, \2009\2009-01-02) and the organizing directory (\2009 in this example) does not contain any photos to locate.  Furthermore, each of my orgainizing 'yearly' directories are organized in one top directory (\Photos) that also has no photos in it to locate.  So, to make use of this feature, I had to create a photo in at least the top directory that I could use for finding the rest.  I call this a 'FindMe' photo.  I found that it needed to have a totally different file name than any other photo in my library.  So, I created on be exporting another photo (with very poor resolution to keep the size small) and giving it a name of FindMe-<directory_name>.  I also found it helpful to give it a caption of 'FindMe' to use in locating the photo.  I imported this photo into the top directory (\Photos) on the PC.
    The next step was to open the .lrcat on the Mac.  Looking at the grid of all photos, I narrowed down the photos to just those that had a caption of 'FindMe' or a file name of FindMe.  That located the photo in \Photos that I could use to start the search for all the rest.  (Note that giving your locating photo a name you can easily find is important because all you will be able to see when you look at all of the photos is just a blank square and I couldn't find any way to tell Lightroom to only show me photos in this one directory, excluding subdirectories (this is a feature they should add to Lightroom).)
    Now theoretically, this trick should have located all of my photos.  However, in a library of over 55,000 photos, there's bound to be some problems.  It turns out that my library that started in Adobe Photoshop Elements had some entries that didn't point to the file properly...in fact there was a blank space at the beginning of the filename.  We had caught this problem and renamed the file on the hard drive properly, but a few catalog entries had missed the correction of the filename before we converted this to a Lightroom catalog.  (Elements tolerated the blank space in the file name, Lightroom does not).  This caused Lightroom to hang when it was locating file.  I solved this problem by fixing a lot of these in the PC catalog.  (This took some doing, because Lightroom would first give me a ? to let me locate the file, but it quickly realized it had a problem and changed the ? to a danger sign that would not allow me to do anything with the photo.  So, I had to act quickly to correct the problem with these photos.)  That fixed a lot, but there were apparently still some problems in the library that caused Lightroom to hang when locating photos.  Also, as the number of photos that were properly relocated grew, I found that it took too long to let Lightroom try to fix the entire library.  So, I started creating FindMe photos in the few remaining 'yearly' organizing directories and locating files in each of these.  That pretty much did the trick.
    My wishlist for Lightroom new features:
    1.   I would like it if I could tell Lightroom to locate all photos within a directory (with the choice to includ subdirectories) in a particular place.  By this, I mean to go from the directory, not from a specific photo within a directory.
    2.  I want to be able to tell Lightroom to only display photos within a particular directory (excluding those in the subdirectory).  This would make it a lot easier to locate my 'find me' photos and would eliminate the need to make the so identifiable.

  • How can I use the same domain.sites2 on two macs?

    I know iWeb is no longer supported but I still find it ok to manage my web site.
    I would like to work on the site from two macs. I thought I could just use the same Domain.sites2 on both macs but: if I move Domain.sites2 to dropbox folder, when I launch iWeb it does not know about it and creates a new empty Domain.sites2 in the Library/iWeb folder
    I do not want to have to manually make a copy of Domain.sites2 to Dropbox and then to the other mac's Library every time I switch computer.

    You may want to use :
    http://wyodor.byethost8.com/iwebsites/iWebSites.html
    Select "Choose new folder" from the File menu to select the folder on Dropbox where your domain file is.
    If that does not work, use:
    http://wyodor.byethost8.com/iwebsites/iWebDrop.zip
    (Unzip the file and drop the domain file on top of it)
    After that, you can open iWeb with your currently used domain file.

  • How can I use my external hard drive on my mac and a windows computer?

    Hello,
    Can anyone help...I have recently purchased a new external hard drive for my macbook pro, it is a 1TB hard drive. I use it for time machine back ups which only takes up about 250gb of space so obviously I have a lot more to use. I'm at University and the computers there are Windows so I'm hoping to be able to drag my uni work to my external HD and connect it to the windows computers at my university so that I have my work there as well - however I'm not sure how I should format my HD???
    Thanks

    You will eventually use all of that 1TB external for the Time Machine backups, that is if you do regular Time Machine backups (It is NOT a One Time thing). So using that same external for anything else is not a good idea.
    You would be much better off buying a large USB thumb drive, like 64GBs in size, and format that to one of the Windows formates that both Mac OS X and Windows can read from and write to. Those would be FAT32 and exFAT. If you are moving file less than 4GBs in size then format it FAT32. You can then copy files to it from your Mac and Read those files on the Windows PCs the school has and just stick that Thumb drive in your pocket.

  • How can I use bluetooth to send data to my mac book pro?

    I can connect my smartphone (nokia) to my Mac Book Pro, but if I try to send something from Nokya to my Mac using bluetooth, that's impossible. The only way is to search what I wanto to store in my Mac, using the Mac and browse my Nokia with Finder.
    Is this correct ??
    Is the bluetooth an univesral protocol to send and receive data between two sources ???
    Why my Mac is unable to receive the data sended by another source ?? (the same question is valid using an iPhone and another smartphone to try to send/receive data).
    Many thank for your response.
    Ezio

    I have many movies I made in iMovie and need to burn to DVD for players.
    You need this:   http://www.apple.com/findouthow/movies/idvd.html#custom
    IDVD is a wonderful piece of software and well worth the low cost of $40.
    http://www.amazon.com/Apple-MC623Z-A-iLife-VERSION/dp/B003XKRZES/ref=sr_1_1?ie=U
    http://dealmac.com/lw/artclick.html?1,527850,1872219

  • How can I use a setup.exe file on my mac

    I am attempting to download a demo software on my mac. It uses a setup.exe and I am unable to make it execute. I do have microsoft office on my mac.

    You need to be running Windows to use that software:
    Windows on Intel Macs
    There are presently several alternatives for running Windows on Intel Macs.
    1. Install the Apple Boot Camp software.  Purchase Windows XP w/Service Pak2, Vista, or Windows 7.  Follow instructions in the Boot Camp documentation on installation of Boot Camp, creating Driver CD, and installing Windows.  Boot Camp enables you to boot the computer into OS X or Windows.
    2. Parallels Desktop for Mac and Windows XP, Vista Business, Vista Ultimate, or Windows 7.  Parallels is software virtualization that enables running Windows concurrently with OS X.
    3. VM Fusionand Windows XP, Vista Business, Vista Ultimate, or Windows 7.  VM Fusion is software virtualization that enables running Windows concurrently with OS X.
    4. CrossOver which enables running many Windows applications without having to install Windows.  The Windows applications can run concurrently with OS X.
    5. VirtualBox is a new Open Source freeware virtual machine such as VM Fusion and Parallels that was developed by Solaris.  It is not as fully developed for the Mac as Parallels and VM Fusion.
    6. Last is Q.  Q is a freeware emulator that is compatible with Intel Macs.  It is much slower than the virtualization software, Parallels and VM Fusion.
    Note that Parallels and VM Fusion can also run other operating systems such as Linux, Unix, OS/2, Solaris, etc.  There are performance differences between dual-boot systems and virtualization.  The latter tend to be a little slower (not much) and do not provide the video performance of the dual-boot system. See MacTech.com's Virtualization Benchmarking for comparisons of Boot Camp, Parallels, and VM Fusion. Boot Camp is only available with Leopard or Snow Leopard. Except for Crossover and a couple of similar alternatives like DarWine you must have a valid installer disc for Windows.
    You must also have an internal optical drive for installing Windows. Windows cannot be installed from an external optical drive.

  • How can i use fax fuction in my i Mac

    How can I use the fax function on my i Mac with OSX 10.8.2?
    1. I am using fax machine Epson Syylu Office TX510FN which has PC-Fax function, but support OSX 10.7.
    2. Which Fax machine type has a soft ware can back up OSX 10.8.2?

    Are you saying the fax features no longer work in Mountain Lion?  That would surprise me; I wouldn't think Apple would have done non-backward-compatible changes to the built-in drivers. 
    First thing I'd try is to redo the stylus setup: connect it by usb (if it's not already so connected) and run through the setup procedure.  you might also try downloading the OS X drivers from the Epson website; they claim it should work on 10.3+

  • How can i use Progress bar in IR Report

    Hi ,
    I have created IR Report based on the View so, it's been taking 10-15 mins of time to execute the IR Report. Here user want to see the Progress bar while executing the IR Report. How can i use Progress bar in IR Report.
    Anybody have idea on Progress bar please help me.
    Regards
    Narender B

    Hi ,
    Thanks for your information.
    I am new to the APEX.*i need to show Progress bar while opening the each page* then user can know some process is happening from the backside and i don't know where i need to add and call the below function.could you please provide the steps for the progress bar.
    In my application there are almost 100 pages are there so, i need to show progress bar on each page while opening .could you please provide Global function to call on each page.
    function html_url_Progress(pThis){ 
    $x_Show('AjaxLoading');
    window.setTimeout('$s("AjaxLoading",$x("AjaxLoading").innerHTML)', 100);
    //doSubmit('APPLY_CHANGES');
    redirect(pUrl);
    Regards
    Narender B

Maybe you are looking for

  • Editing (Setting and Removing) CLASSPATH on Snow Leopard

    I am trying to learn XSLT, and so I am installing Xerces and Xalan - but I have to add certain .jar's to the classpath. This is extremely easy on the PC, but how do I change this on the Mac? I would like to set it into an environment variable if poss

  • Help Using Instant Client ODBC on Linux

    I am familiar with using ODBC and visual basic under Windows. I would like to use the Oracle instant client ODBC under Red Hat ES3 within a C or C++ program to access an Oracle database. Where can I find documentation related to this: a) setting up a

  • SQL*Plus Worksheet formating

    I have Oracle Client 8.1.7 installed in my computer, and I can't seem to have the desired output format with the SQL*Plus worksheet. I have a database where the tables have several column, and most of these columns are text with 1024 characters lengt

  • IPhoto Doesn't recognize my camera and my macbook won't connect to it

    Have a Kodak EasyShare V610. Can't get the camera to connect to the macbook and have iPhoto acknowledge it. Tried the blue tooth (which previously worked) and can't connect using the USB cable either. Recently had a hard drive failure and have been h

  • Database Analyst/Adminstration and support

    This may seem a bit "green" of me to ask this question, but I was wondering as a DBA (not quite sure what the difference between an adminstrator and analyst are), is "on call support" always a necessity? Currently I am working as a programmer, but al