2012-01-02 13 views
1

NewsstandKitに移行して、バックグラウンドダウンロードの恩恵を受けようとしています。NKAssetDownload destinationURLがファイルまたはディレクトリとして存在しません

NKAssetDownloadを開始して代理人を設定できるようになりました。しかし、ダウンロードしたコンテンツを入手するには、ファイルシステムから取得することができません。

特定のパラメータを持つコンテンツをCMSに照会していますが、ファイルのダウンロードが返されます。ダウンロードは正常に進行しますが、その後にファイルが見つかりません。

これはダウンロードデリゲートに対応するコードです:

- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *)destinationURL { 

#if DEBUG 
    NSLog(@"NewsstandTracker.m connectionDidFinishDownloading destinationURL:%@",destinationURL); 

    NSLog(@"========= destination url contents ======="); 


    NSFileManager *manager = [[[NSFileManager alloc] init] autorelease]; 

    NSError *error = nil; 
    BOOL isdir = 0; 
    BOOL exists = [manager fileExistsAtPath:[destinationURL absoluteString] isDirectory:&isdir]; 
    NSLog(@"file exists: %d isDir:%d",exists,isdir); 
    NSLog(@"error: %@",error); 
    NSString *f = [[[assetDownload URLRequest] URL] lastPathComponent]; 
    NSDirectoryEnumerator * enumerator = [manager enumeratorAtPath:[[destinationURL absoluteString]stringByAppendingPathComponent:f]]; 

    for (NSString *url in enumerator) { 

     NSLog(@"%@",url); 
    } 



    NSLog(@"======= contentURL contents ======="); 

    manager = [[[NSFileManager alloc] init] autorelease]; 
    NSDirectoryEnumerator * en = [manager enumeratorAtPath:[[[self getNewsstandIssue] contentURL] absoluteString]]; 


    for (NSString *url in en) { 

     NSLog(@"%@",url); 
    } 

#endif 
//do more stuff according to NewsstandKit docs 

これは、私も行うことができます前に、何とかがダウンロードを片付けているように見えるコンソール

2012-01-02 16:01:45.843[499:707] NewsstandKit: cleaning up abandoned asset downloads: (
    "<NKAssetDownload: 0x36dc510> -> {identifier: '75F48F44-ADF9-4F83-ABF6-5C03F57524C1/508E80A2-A8AA-4DD1-A979-715395E4E8DD' request: <NSURLRequest http://server-content/getFreeIssue/a_product_id> downloading: NO}" 
) 
2012-01-02 16:02:43.613[499:707] NewsstandTracker.m connectionDidFinishDownloading destinationURL:file://localhost/private/var/mobile/Applications/992490C5-2607-4942-B06D-4EE9CD6226E4/Library/Caches/bgdl-499-2e4c509b06864f5c.issue23 
2012-01-02 16:02:43.614[499:707] ========= destination url contents ======= 
2012-01-02 16:02:43.614[499:707] file exists: 0 isDir:0 
2012-01-02 16:02:43.615[499:707] error: (null) 
2012-01-02 16:02:43.616 GSMagazine[499:707] ======= contentURL contents ======= 

の出力でありますそれと何か。

手がかりはありますか?

+0

以下のいずれかの解決策が問題を解決したか、解決策を見つけましたか(または放棄しましたか)。 –

答えて

0

これは、NewsStandのダウンロードに移動した後も同じ問題です。 iOSは、アプリケーションの起動時に再開しない保留中のダウンロードをキャンセルします。 UIApplicationのdidFinishLaunchingWithOptionsで

NKLibrary *nkLib = [NKLibrary sharedLibrary]; 
for(NKAssetDownload *asset in [nkLib downloadingAssets]) { 
    NSLog(@"Asset to downlaod: %@",asset); 
    [asset downloadWithDelegate:Downloader]; 
} 

:これは、あなたがダウンロードを復元する必要がdidFinishLaunchingWithOptionsメソッドに

NSUInteger count = [[NKLibrary sharedLibrary] downloadingAssets].count; 
     for(NSUInteger i = 0 ; i < count ; i++) 
     { 
      MAZDebugLog(@"We have some pending downloads"); 
      NKAssetDownload *asset = [[[NKLibrary sharedLibrary] downloadingAssets] objectAtIndex:i]; 

[asset downloadWithDelegate:self]; 

     } 
1

Pacu [destinationURL absoluteString]の代わりに[destinationURL path]を使用してください。ファイルマネージャは、URLではなく文字列形式のURLを使用します。

0

を行うべきです。

残念ながら私にとってはUIViewとコントローラの初期化の前にしか動作しません。私はこのコードをapplicationDidBecomeActiveに入れようとしましたが、アプリケーションがオフラインで実行されても正しく動作しません。

関連する問題