ios - Determine if image picker media type is video -
i've seen various methods checking whether returned media type in -imagepickercontroller:didfinishpickingmediawithinfo: video. example, way:
- (void)imagepickercontroller:(uiimagepickercontroller *)imagepicker didfinishpickingmediawithinfo:(nsdictionary *)info { if (uttypeequal(kuttypemovie, (__bridge cfstringref)[info objectforkey:uiimagepickercontrollermediatype])) { // ... } } or
nsstring *mediatype = [info objectforkey:uiimagepickercontrollermediatype]; if ([mediatype isequaltostring:(nsstring *)kuttypemovie]) { or
if ([mediatype isequaltostring:(nsstring *)kuttypevideo] || [mediatype isequaltostring:(nsstring *)kuttypemovie]) or
if (cfstringcompare ((__bridge cfstringref) mediatype, kuttypemovie, 0) == kcfcompareequalto) or
if ([mediatype isequaltostring:@"public.movie"] everyone seems have different way of doing this. what's recommended method checking media type? preferably way include "all image types" or "all video types".
it better check conformance particular uti instead.
right now, ios tells public.movie, next year? you'll see people checking public.video well. great, you've hard-coded 2 types instead of one.
but wouldn't better ask "is movie?" rather hard code specific type think ios return? there's way that:
nsstring *mediatype = info[uiimagepickercontrollermediatype]; bool ismovie = uttypeconformsto((__bridge cfstringref)mediatype, kuttypemovie) != 0; using approach, ismovie should yes if movie returned (regardless of specific type returned) if mediatype represents movie, since movies conform kuttypemovie. clear, if kuttypevideo recognize movie, because kuttypevideo conforms kuttypemovie.
likewise, can check see if thing returned image:
nsstring *mediatype = info[uiimagepickercontrollermediatype]; bool isimage = uttypeconformsto((__bridge cfstringref)mediatype, kuttypeimage) != 0; isiamge should yes if image returned, since images conform kuttypeimage.
see apple's (partial) type tree here: uniform type identifiers declared in conformance hierarchy. can less useful more complete list of utis recognized system , conformance shell with:
/system/library/frameworks/coreservices.framework/frameworks\ /launchservices.framework/versions/a/support/lsregister -dump in particular, can see public.video defined this:
-------------------------------------------------------- type id: 8344 uti: public.video description: video flags: exported active core apple-internal trusted icon: conforms to: public.movie tags: -------------------------------------------------------- note uttypeconformsto returns true if types same well. apple's docs:
returns true if uniform type identifier equal or conforms second type.
Comments
Post a Comment