Pergunta

I have a piece of code that as far as I can tell should work fine, but isn't:

NSMutableDictionary* videos = [NSMutableDictionary dictionary];
VideoObject* localVideo = [VideoObject videoObject];
localVideo.assetURL = url;//trust me it's set
localVideo.localThumbPath = finalPath;
        videoData = [NSKeyedArchiver archivedDataWithRootObject:localVideo];
        [videos setObject:videoData forKey:localVideo.assetURL];
        if(![videos writeToURL:[NSURL URLWithString:self.cacheFilePath] atomically:YES]){
            NSLog(@"pretest videos:%@\
                  data:%@\
                  class of key:%@ class of value:%@",videos,videoData,NSStringFromClass([localVideo.assetURL class]),NSStringFromClass([videos[localVideo.assetURL] class]));
        }

I have setup all the encoding stuff in the VideoObject class. lovalVideo.assetURL is of type NSString. Everything looks like it should work perfectly to me, but it always returns NO on the writeToURL. Here is the output I get fromt he log:

pretest videos:{ "http://example.org/test.mov" = <62706c69 73743030 d4010203 0405082e 2f542474 6f705824 6f626a65 63747358 24766572 73696f6e 59246172 63686976 6572d106 0754726f 6f748001 ab090a1f 20212223 24252627 55246e75 6c6cda0b 0c0d0e0f 10111213 14151617 18191a1b 1c1d1e57 6170696e 616d655e 6c6f6361 6c546875 6d625061 74685961 70696175 74686f72 596c6f63 616c5061 74685861 70697469 746c6557 61706970 6174685c 61706974 68756d62 6e61696c 57617069 74797065 5624636c 6173735c 706f7374 5f636f6e 74656e74 80028009 80048000 80038007 80088005 800a8006 5444424d 53566768 6873766a 55676976 656e596d 6f6e6f6c 6f677565 55476c65 6e6e5f10 3f687474 703a2f2f 61727470 6c617961 73632e6f 72672f77 702d636f 6e74656e 742f7570 6c6f6164 732f6170 705f7570 6c6f6164 732f6768 6873766a 2e6d6f76 5f104268 7474703a 2f2f6172 74706c61 79617363 2e6f7267 2f77702d 636f6e74 656e742f 75706c6f 6164732f 6170705f 75706c6f 6164732f 7468756d 626e6169 6c2e6a70 675f1094 2f766172 2f6d6f62 696c652f 4170706c 69636174 696f6e73 2f443337 34313232 392d3536 44452d34 3931412d 42444436 2d424530 41463931 43413234 452f4c69 62726172 792f4361 63686573 2f415349 48545450 52657175 65737443 61636865 2f506572 6d616e65 6e745374 6f72652f 46303846 36343633 36454646 46363533 44363234 36354641 45324142 36433931 2e6a7067 d228292a 2d582463 6c617373 65735a24 636c6173 736e616d 65a22b2c 5c566964 656f4461 74614f62 6a584e53 4f626a65 63745c56 6964656f 44617461 4f626a12 000186a0 5f100f4e 534b6579 65644172 63686976 65720008 00110016 001f0028 00320035 003a003c 0048004e 0063006b 007a0084 008e0097 009f00ac 00b400bb 00c800ca 00cc00ce 00d000d2 00d400d6 00d800da 00dc00e1 00e800ee 00f800fe 01400185 021c0221 022a0235 02380245 024e025b 02600000 00000000 02010000 00000000 00300000 00000000 00000000 00000000 0272>; } data:<62706c69 73743030 d4010203 0405082e 2f542474 6f705824 6f626a65 63747358 24766572 73696f6e 59246172 63686976 6572d106 0754726f 6f748001 ab090a1f 20212223 24252627 55246e75 6c6cda0b 0c0d0e0f 10111213 14151617 18191a1b 1c1d1e57 6170696e 616d655e 6c6f6361 6c546875 6d625061 74685961 70696175 74686f72 596c6f63 616c5061 74685861 70697469 746c6557 61706970 6174685c 61706974 68756d62 6e61696c 57617069 74797065 5624636c 6173735c 706f7374 5f636f6e 74656e74 80028009 80048000 80038007 80088005 800a8006 5444424d 53566768 6873766a 55676976 656e596d 6f6e6f6c 6f677565 55476c65 6e6e5f10 3f687474 703a2f2f 61727470 6c617961 73632e6f 72672f77 702d636f 6e74656e 742f7570 6c6f6164 732f6170 705f7570 6c6f6164 732f6768 6873766a 2e6d6f76 5f104268 7474703a 2f2f6172 74706c61 79617363 2e6f7267 2f77702d 636f6e74 656e742f 75706c6f 6164732f 6170705f 75706c6f 6164732f 7468756d 626e6169 6c2e6a70 675f1094 2f766172 2f6d6f62 696c652f 4170706c 69636174 696f6e73 2f443337 34313232 392d3536 44452d34 3931412d 42444436 2d424530 41463931 43413234 452f4c69 62726172 792f4361 63686573 2f415349 48545450 52657175 65737443 61636865 2f506572 6d616e65 6e745374 6f72652f 46303846 36343633 36454646 46363533 44363234 36354641 45324142 36433931 2e6a7067 d228292a 2d582463 6c617373 65735a24 636c6173 736e616d 65a22b2c 5c566964 656f4461 74614f62 6a584e53 4f626a65 63745c56 6964656f 44617461 4f626a12 000186a0 5f100f4e 534b6579 65644172 63686976 65720008 00110016 001f0028 00320035 003a003c 0048004e 0063006b 007a0084 008e0097 009f00ac 00b400bb 00c800ca 00cc00ce 00d000d2 00d400d6 00d800da 00dc00e1 00e800ee 00f800fe 01400185 021c0221 022a0235 02380245 024e025b 02600000 00000000 02010000 00000000 00300000 00000000 00000000 00000000 0272> class of key:__NSCFString class of value:NSConcreteMutableData

so both key and value are valid types. I have actually initialize that cacheFile before now with an empty dictionary so I know I can write there.

Any ideas?

Foi útil?

Solução

It is probably an issue with the NSURL you create for writing. What is the value of self.cacheFilePath? If this is a plain old file path then you need to create the URL like this:

[NSURL fileURLWithPath:self.cacheFilePath];

What you have would only be value if self.cacheFilePath already started with file://.

In either case, make sure self.cacheFilePath represents an absolute file path.

Outras dicas

I second rmaddy's answer.

Looking at the documentation for URLWithString, they suggest: To create NSURL objects for file system paths, use fileURLWithPath:isDirectory: instead.

The return value will also be nil if the string was malformed. So you should check/log the return value from [NSURL URLWithString:self.cacheFilePath]. If it's nil, then that's your problem. Probably using fileURLWithPath:isDirectory: will make the issue go away.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top