objective-c - 使用 ASIHTTPRequest

标签 objective-c ios xcode ios4 asihttprequest

我想知道是否有人可以帮助我解决当设备使用 ASIHTTPREQUEST 进入休眠模式时如何保持应用内购买下载的问题,我做了一个应用程序,其中包含一些要在应用程序中购买和下载的音乐文件,但是例如,如果用户购买并开始下载专辑,如果他的手机进入休眠状态,它就会停止下载!!! 感谢您提出的任何意见,

-(void) downloadAlbum:(NSNumber *)Albumid {
//NSLog(@"%@",Albumid);
//myTable.scrollEnabled = NO;
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

if (CurrentSongID<=CurrentAlbumCount) {
    if (isDownload==FALSE) {    

        Reachability* internetReach = [[Reachability reachabilityForInternetConnection] retain];
        [internetReach startNotifier];
        NetworkStatus netStatus = [internetReach currentReachabilityStatus];

        switch (netStatus)
        {
            case NotReachable:
            {   UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"Top 10" message: @"Check Internet Connectivity" delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
                [someError show];
                [someError release];
                break;
            }

            case ReachableViaWWAN:
            {   
            }
            case ReachableViaWiFi:

            {   NSString *DestinationFileName= [self FileNameGetter:Albumid FileID:CurrentSongID ];
                NSString * URL=[NSString stringWithFormat: @"http://core-4.doubleu.mobi/cdownload/%@/%d.mp3",[self AlbumNameGetter:Albumid],CurrentSongID];

                isDownload=TRUE;
                progressIndicator.hidden=FALSE;
                DownloadedFileName.hidden=FALSE;
                NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Albums" ofType:@"plist"];
                contentArray=[NSMutableArray arrayWithContentsOfFile:plistPath];
                //NSLog(@"%@",contentArray);
                DownloadedFileName.text=[NSString stringWithFormat:@"%d/%d",CurrentSongID ,CurrentAlbumCount];//[CurrentAlbum count]];
                if (!networkQueue) {
                    networkQueue = [[ASINetworkQueue alloc] init];  
                }
                failed = NO;
                [networkQueue setDownloadProgressDelegate:progressIndicator];
                [networkQueue setRequestDidFinishSelector:@selector(nextDownload)];
                [networkQueue setShowAccurateProgress:YES];
                [networkQueue setDelegate:self];
                request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:URL]];
                [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"] 
                                                     stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp3",[self FileNameGetter:Albumid FileID:CurrentSongID ]]]];

                [networkQueue addOperation:request];
                [networkQueue go];
                break;
            }
        }
    }
    else {
        UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"Top 10" message: @"Please wait Until download Completed" delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
        [someError show];
        [someError release];
    }

}
else {
    //NSString *DestinationFileName= [self FileNameGetter:NSCurrentAlbumID FileID:CurrentSongID ];
    //myTable.scrollEnabled = YES;

    switch (CurrentAlbumIDd) {
            //to be modified
        case 1:
        {
            //NSString *DestinationFileName= [self FileNameGetter:NSCurrentAlbumID FileID:CurrentSongID ];
            UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"فضل شاكر" message:[NSString stringWithFormat:@"Download بياع القلوب Completed"] delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
            [someError show];
            [someError release];
            //[Album1 setTag:Album1.tag*100];
            downloaded1 = TRUE;
            available1=1;

            break;}
        case 2:
        {
            UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"فضل شاكر" message:[NSString stringWithFormat:@"Download الحب القديم Completed"] delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
            [someError show];
            [someError release];
        //  [Album2 setTag:Album2.tag*100];
            downloaded2 = TRUE;
            available2=1;
            break;
        }
        case 3:
        {
            UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"فضل شاكر" message:[NSString stringWithFormat:@"Download حبك خيال Completed"] delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
            [someError show];
            [someError release];
        //  [Album3 setTag:Album3.tag*100];
            downloaded3 = TRUE;
            available3=1;
            break;
        }

最佳答案

您可以在 How To Use Page 上找到所有需要的信息来自 ASIHTTPRequest Doku

  1. Resuming downloads

  2. Download in Background

setShouldContinueWhenAppEntersBackground:YES 设置为您的请求

 request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:URL]];
 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"] 
                                                 stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp3",[self FileNameGetter:Albumid FileID:CurrentSongID ]]]];
[request setShouldContinueWhenAppEntersBackground:YES];

关于objective-c - 使用 ASIHTTPRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10210235/

相关文章:

objective-c - 应用程序上的捆绑资源未更新。

objective-c - arrayByAddingObjectsFromArray?

ios - 随机化按钮的音频

iOS 围绕 anchor 旋转 View 并跟随触摸

ios - 项目中相同语言的多个 .string 文件

ios - 将 txt 文件读入 iOS 应用程序时出错

objective-c - 如何创建水平 UIPickerView 样式控件?

iphone - 什么是0xdb8844?

ios - UIActivityIndi​​cator 设置颜色在较旧的 iOS 版本上崩溃

ios - 我可以让 UISearchBar 成为它自己的 .inputAccessoryView 吗?