0

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

-(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;
        }
4

1 回答 1

2

您可以在ASIHTTPRequest Doku的如何使用页面上找到所有需要的信息

  1. 恢复下载

  2. 在背景下载

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];
于 2012-04-18T13:26:26.893 回答