2010-12-15 2 views
0

Eyのみんな、ここに私のコードは次のとおりです。NSURLDownloadは、SDK 4.2で検出されない

#import <Foundation/Foundation.h> 
@interface Updater : NSObject { 

    NSURLConnection *updateConnection; 
    NSURLDownload *downloadConnection; //error at this line 

} 

@end 

これは私がマークされたラインで取得していますエラーです:

Updater.h:15: error: expected specifier-qualifier-list before 'NSURLDownload' 

私は取得していますなぜすべてのアイデアをこのエラーメッセージ?私はFoundation Frameworkを組み込みました。なぜなら、特にコンパイラがNSURLConnectionについて全く不平を言っていないと考えると、コンパイラがなぜ不平を言っているのか困っています。ありがとう!

答えて

2

NSURLDownloadクラスはMac OSでのみ利用できます.iOSではNSURLConnectionを使用する必要があります。 docsから:

のiOS注:NSURLDownloadクラス が システムが推奨されたファイルを直接ダウンロードするために、iOS版では使用できません です。あなたがダウンロードして、あなたがメモリにそれを維持するのではなく、ディスクに直接受信したデータを書き込むために接続デリゲートにNSFileHandleクラスを使用することができ、メモリの問題を回避したいデータの大きな塊を持っている場合は NSURLConnectionクラスの代わりに

を使用してください。

+0

素晴らしい、おかげで私。私はドキュメントを読んだが、私はそれについてすべて忘れてしまった。再度、感謝します! – Stunner

1

あなたがiOSで読んでいるように注意:まだNSURLDownloadをiOS上で使用することはできませんが、下のリンクでは、ネットからアプリケーションサンドボックスに簡単にダウンロードできます。あなたがそれを好きだと思います。 乾杯 http://www.ifans.com/forums/showthread.php?t=169611

------------以下は、リンクにすることを指摘して------------

// 
// UIDownloadBar.h 
// UIDownloadBar 
// 
// Created by John on 3/20/09. 
// Copyright 2009 Gojohnnyboi. All rights reserved. 
// 

#import <UIKit/UIKit.h> 

@class UIProgressView; 
@protocol UIDownloadBarDelegate; 

@interface UIDownloadBar : UIProgressView { 
    NSURLRequest* DownloadRequest; 
    NSURLConnection* DownloadConnection; 
    NSMutableData* receivedData; 
    NSString* localFilename; 
    id<UIDownloadBarDelegate> delegate; 
    long long bytesReceived; 
    long long expectedBytes; 

    float percentComplete; 
} 

- (UIDownloadBar *)initWithURL:(NSURL *)fileURL progressBarFrame:(CGRect)frame timeout:(NSInteger)timeout delegate:(id<UIDownloadBarDelegate>)theDelegate; 

@property (nonatomic, readonly) NSMutableData* receivedData; 
@property (nonatomic, readonly, retain) NSURLRequest* DownloadRequest; 
@property (nonatomic, readonly, retain) NSURLConnection* DownloadConnection; 
@property (nonatomic, assign) id<UIDownloadBarDelegate> delegate; 

@property (nonatomic, readonly) float percentComplete; 

@end 

@protocol UIDownloadBarDelegate<NSObject> 

@optional 
- (void)downloadBar:(UIDownloadBar *)downloadBar didFinishWithData:(NSData *)fileData suggestedFilename:(NSString *)filename; 
- (void)downloadBar:(UIDownloadBar *)downloadBar didFailWithError:(NSError *)error; 
- (void)downloadBarUpdated:(UIDownloadBar *)downloadBar; 

@end 


// 
// UIDownloadBar.m 
// UIDownloadBar 
// 
// Created by John on 3/20/09. 
// Copyright 2009 Gojohnnyboi. All rights reserved. 
// 

#import "UIDownloadBar.h" 


@implementation UIDownloadBar 

@synthesize DownloadRequest, 
    DownloadConnection, 
    receivedData, 
    delegate, 
    percentComplete; 


- (UIDownloadBar *)initWithURL:(NSURL *)fileURL progressBarFrame:(CGRect)frame timeout:(NSInteger)timeout delegate:(id<UIDownloadBarDelegate>)theDelegate { 
    self = [super initWithFrame:frame]; 
    if(self) { 
     self.delegate = theDelegate; 
     bytesReceived = percentComplete = 0; 
     localFilename = [[[fileURL absoluteString] lastPathComponent] copy]; 
     receivedData = [[NSMutableData alloc] initWithLength:0]; 
     self.progress = 0.0; 
     self.backgroundColor = [UIColor clearColor]; 
     DownloadRequest = [[NSURLRequest alloc] initWithURL:fileURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:timeout]; 
     DownloadConnection = [[NSURLConnection alloc] initWithRequest:DownloadRequest delegate:self startImmediately:YES]; 

     if(DownloadConnection == nil) { 
      [self.delegate downloadBar:self didFailWithError:[NSError errorWithDomain:@"UIDownloadBar Error" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"NSURLConnection Failed", NSLocalizedDescriptionKey, nil]]]; 
     } 
    } 

    return self; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    [self.receivedData appendData:data]; 

    NSInteger receivedLen = [data length]; 
    bytesReceived = (bytesReceived + receivedLen); 

    if(expectedBytes != NSURLResponseUnknownLength) { 
     self.progress = ((bytesReceived/(float)expectedBytes)*100)/100; 
     percentComplete = self.progress*100; 
    } 

    [delegate downloadBarUpdated:self]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
    [self.delegate downloadBar:self didFailWithError:error]; 
    [connection release]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
    expectedBytes = [response expectedContentLength]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
    [self.delegate downloadBar:self didFinishWithData:self.receivedData suggestedFilename:localFilename]; 
    [connection release]; 
} 

- (void)drawRect:(CGRect)rect { 
    [super drawRect:rect]; 
} 

- (void)dealloc { 
    [localFilename release]; 
    [receivedData release]; 
    [DownloadRequest release]; 
    [DownloadConnection release]; 
    [super dealloc]; 
} 


@end 
+0

共有ありがとう! – Stunner

関連する問題