QTMovie opened movie successfully? - objective-c

Is there any way to detect whether QTMovie successfully loaded a movie? I.E. whether a valid component is found?
Or even better enumerate the components on launch and detect then what components have been loaded without having to provide a sample movie?
Thanks.

Have you read the QTMovie API reference? When you try to create a QTMovie object, you'll get either a valid movie object or nil. If you make use of the NSError argument (that's included on all the initializers/factory methods that create movies from files/URLs), you'll even get an explanation of what went wrong if the method returns nil. Also in that reference (handily categorized in the Tasks section), are a number of ways to get pretty much any information about the movie you want.
Regarding the "components" part of your question, I don't think QTKit gives you access to this directly. You might have to use the QuickTime.framework and dive deeper. You might be able to figure out whether your third-party-supported file type is actually supported by using the +[QTMovie movieFileTypes:] method (also found in the API reference I linked) and seeing if your file's extension appears there.

Related

Iterate through photo library on OS X?

I'm trying to iterate through a user's photo library on OS X. On iOS, I would use the Photos framework, but apparently that's not available on OS X, and we're supposed to use the Media Library framework instead. However, while I was able to use the code linked above to get access to a MLMediaSource object, I'm having a hard time figuring out how to iterate through the photo assets.
The Media Library Framework documentation makes reference to a mediaObjectForIdentifier: method, which sounds promising, but doesn't indicate what sort of identifiers should be used. I'm fairly experienced with iOS, but a complete n00b on OS X, so I'm feeling a little lost.
If I just wanted to iterate through a user's library, NSLog'ing each photo, how might I go about that? Either using the Media Library Framework, or another framework so long as it works for the current Photos library?
This framework isn't hard to work with, but it is tedious because it async/lazy loads the properties, and KVO is the only want to be notified about the async completion.
If you want to iterate the photos, you don't need to know the identifiers in advance.
Create a media library:
self.library = [[MLMediaLibrary alloc] initWithOptions:options];
Add a KVO observer for mediaSources. Access mediaSources, if non-nil, go to the next step, otherwise go to the next step when your KVO observer fires.
In the next step, iterate the sources, add a KVO observer on rootMediaGroup, and access rootMediaGroup on each source. If it is non-nil, call your iterator now, otherwise call it from the KVO notification handler.
For each rootMediaGroup, follow the same strategy as above, but for mediaObjects. The media objects are the things you are ultimately after.

Do category names get serialized with encodeWithCoder style marshalling?

I have an app that is storing some data using the Cocoa/ObjC initWithCoder / encodeWithCoder style marshaling. Over the life of the app one of the classes that has been removed is an NSDate+Utils category.
The question is - if an NSDate+Utils is serialized to disk, and then deserialized with a later codebase when NSDate+Utils no longer exists; will it come back as an NSDate, or will it crash??
It won't crash. You just need to check whether it's nil. If that' nil, then just skip it, otherwise populate the data to your property. By the way, there is nothing to do with the codebase. It's just whether that local data being stored in the device. Codes are just things that tell device what or how to do stuff.
I wrote a small program to test this. Categories seem to get written as the base class - I assume as long as they don't add fields and/or mess with the withCoder methods.

I'm having trouble applying a solution found in SO in my iOS app. Can someone show me the big picture?

in the Stack Overflow posting:
How do I create a global UIManagedDocument instance per document-on-disk shared by my whole application using blocks?
Alan asked how to create a global UIManagedDocument to be used throughout his entire app. He provided code slices of his attempt. Kevinpo provided an answer which made perfect sense to Alan.
But I started out with the same problem, and can't make heads or tails out of their collective postings.
Specifically:
Alan's code references an object called managedDocumentDictionary,
but does not explain how to create it so I get an 'undeclared
identifier' compilation error.
Alan starts out stating that he wants to create a helper method to
retrieve a UIManagedDocument, yet throughout both his and Kevin's
code, neither actually show defining a helper method with .h and .m
files.
So, if possible, can anyone make sense of what they are saying and help me understand how it all fits together? Perhaps:
A helper Class definition,
How does one get the ball rolling, i.e., where do I initially create this UIManagedDocument,
Once created, How do I get the document in other TableViewControllers?
A sample of where this should be invoked - in the AppDelegate? or each TableViewController?
Maybe even a sample project?
Thanks to all for any interpretations you can offer.
That post shows how to access a document, based on a name. The dictionary is a mapping from names to UIManagedDocument instances. Thus, he can ask for document #"Foo" and the code will go look up #"Foo" in the dictionary. If it is there, the UIManagedDocument will be returned. If it is not there, then a new one will be created and placed in the dictionary (and the passed-in completion block will be called).
His question was basically, how to pass a completion block to the function, and have that function call the completion block he passed in.

iOS writing to asset library observations

I am attempting to write an app that reads images from the asset library, modifies the image's GPS data and writes it back to the asset library. I store the assets in a mutableArray via the "enumerating assets" methods. Most of the details on how to do the various steps, I got from searching this forum. Thanks!
I have found that when I write the first "asset" via the "writeimagedatatosavedphotosalbum" method, all the elements of the mutableArray associated with the assets' URL became null. Furthermore, I noticed that writing back an image does not replace the original image, but instead creates a second instance of the image.
Just thought I'd pass these results along, in case others had questions. And, of course, I'd be interested in other's comments, observations, etc.
This forum has provided me with great information. Thanks again.
Your ALAsset object is only as good for the amount of time that your ALAssetsLibrary object is around. You either need to do everything you want in the completion block when you get the ALAsset, or store the ALAssetsLibrary in an instance variable so ARC does not deallocate it.
An ALAsset is essentially a Core Data object who can have properties accessed from multiple threads but a NSManagedObject or a subclass of NSManagedObject does not make sense without a parent NSManagedObjectContext much in the same way an ALAsset doesn't make sense without an ALAssetsLibrary.
It is common practice to store the NSManagedObjectContext on the AppDelegate; and while I abstract that functionality into a wrapper/singleton there is a retained reference to the NSManagedObjectContext throughout the app lifecycle. Apply the same logic to the ALAssetsLibrary and everything will works as expected.

What does "+resetStandardUserDefaults" actually do?

Have tried to use "+resetStandardUserDefaults" of the NSUserDefaults class to reset the default values to their "factory" settings. It turns out to be not the appropriate method to use. Find out from some archived discussions in SO that we should use the instance method "removeObjectForKey" to remove the user's settings instead.
But am just curious and hope that someone could explain the actual usage of "+resetStandardUserDefaults". Have read the reference web manual about this. But it is very brief and I don't seem to get what it really means ...
Somewhere (usually in the app delegate +initialize) you declare the standard user defaults (preferences of your app at the first launch).
+resetStandardUserDefaults makes your app mean it's the first launch and uses the user defaults the way you declared them in the app delegate.
THE ABOVE IS THE WRONG ANSWER
As Apple's documentation says, it:
Synchronizes any changes made to the shared user defaults object and releases it from memory
The reset portion refers to the fact that the standardUserDefaults object in memory is destroyed, so you get a fresh one from the file system next time you use [NSUserDefaults standardUserDefaults] but it has nothing to do with any first launch behaviour.
The call would make sense if it was renamed flushDefaultsToDisk or similar. It is the most misleadingly-named part of iOS SDK I've seen so far.
(I corrected this in-place as this rates quite highly on searches and didn't want to put the correction in a comment which someone might not read.)