iOS Question Huge Download with Progress

Discussion in 'iOS Questions' started by Alberto Iglesias, Jul 20, 2015.

  1. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    Hello,

    The Http2Utils class not support progress download monitoring?

    Do you have another class or native code to do this?

    i´m working in a app to download videos from youtube, but I can see the downloaded %

    Thanks.

    Alberto Iglesias
     
  2. Pendrush

    Pendrush Active Member Licensed User

    Not related to question, just to warn you. Every app that download or convert videos from YouTube is forbidden on app store.

    More on link: https://developer.apple.com/app-store/review/guidelines/
     
  3. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    we know that, this app in a internal one, is not to go to store!

    I need progress in any download (files, videos, etc)

    Tks
     
  4. JanPRO

    JanPRO Well-Known Member Licensed User

    Hi,

    use NSURLConnection.

    Here is an little example:

    I want to load this 4k image into an ImageView:
    Code:
    Sub Download_Complete
    Log("File was successfully downloaded")

    Dim BM As Bitmap
    BM.Initialize(
    File.DirDocuments,"Mountains.jpg")
    ImageView1.Bitmap = BM
    End Sub

    Sub Download_Error(ErrorMessage As String)
    Log(ErrorMessage)
    End Sub

    Sub Button1_Click
    Dim NativeMe As NativeObject = Me
    NativeMe.RunMethod(
    "Download:::::",Array("http://data.hdwallpapers.im/nature_mountain_4k.jpg",ProgressView1,Label1,File.DirDocuments,"Mountains.jpg"))
    End Sub


    #If OBJC

    UIProgressView * ProgressBar;

    NSURLResponse *DownloadedResponse;
    NSMutableData *DownloadedData;
    NSString *FilePath;
    UILabel *ProgressLabel;

    -(void)Download: (NSString *)FileUrl :(UIProgressView *)ProgressBarToSet :(UILabel *)LabelToSet :(NSString *)Directory :(NSString *)FileName
    {
       ProgressBar = ProgressBarToSet;
       ProgressBar.progress = 0;

       ProgressLabel = LabelToSet;

       FilePath = [Directory stringByAppendingString: FileName];

       DownloadedData = [[NSMutableData alloc] init];
       NSURL *url = [NSURL URLWithString:FileUrl];
       NSURLRequest *request = [NSURLRequest requestWithURL:url];
       NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
    }

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
       [DownloadedData appendData:data];
       ProgressBar.progress = ((100.0/DownloadedResponse.expectedContentLength)*DownloadedData.length)/100;

       NSString * LabelText = [[NSString stringWithFormat:@"%0.f", (ProgressBar.progress * 100)] stringByAppendingString:@"%"];
       ProgressLabel.text = LabelText;
    }

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
       [DownloadedData writeToFile:FilePath atomically:YES];
       [self.bi raiseEvent:nil event:@"download_complete" params:@[]];
    }

    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
       [self.bi raiseEvent:nil event:@"download_error:" params:@[error.localizedDescription]];
    }

    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
      DownloadedResponse = response;
    }

    #End If
    based on: http://www.devfright.com/ios-data-download-progress-bar-tutorial/
     
    Last edited: Jul 20, 2015
    ilan, schimanski and cloner7801 like this.
  5. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    Perfect JanPRO, I will try right now!

    Super Thanks!
     
  6. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    JanPro,

    This code work like a charm!


    THANK YOUUUUUUUUUUUUUUUUUUUUUUU!!!


    look:

    [​IMG]
     
  7. chjk

    chjk Member Licensed User

    It's very good! Do you know ftp how to download or upload file show process?
     
  8. cloner7801

    cloner7801 Active Member Licensed User

    How can we show connection speed ?
     
  9. schimanski

    schimanski Well-Known Member Licensed User

    Is it possible to use this method with parameters linke Download2?

    Code:
    job.Download2("http://www.example.com", _
        
    Array As String("key1""value1""key2""value2"))
    I have to send the access data to the server.

    Thanks for help...
     
  10. JanPRO

    JanPRO Well-Known Member Licensed User

    schimanski likes this.
  11. schimanski

    schimanski Well-Known Member Licensed User

    Is perfect! Thank you:)
     
  12. ilan

    ilan Expert Licensed User

    Can u share the code how to download a video from youtube?

    Is it possible to rip the audio from it to mp3?

    Thsnx
     
Loading...