2012-09-19 37 views
7

Kullanıcıların videoları videoya bırakmasına izin veren bir uygulama yapıyorum. Bırakılan NSURL * lerin bir listesi göz önüne alındığında, her birinin public.movie UTI türüne uygun olduğundan nasıl emin olabilirim?UTI/dosya türü için NSURL'yi kontrol edin

Bir NSOpenPanel vardı, ben sadece openPanel.allowedFileTypes = @[@"public.movie"]; kullanırdım ve Cocoa benim için onunla ilgilenirdi.

Şimdiden teşekkürler!

cevap

17

Bu çalışması gerekir:

NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; 

for (NSURL *url in urls) { 
    NSString *type; 
    NSError *error; 
    if ([url getResourceValue:&type forKey:NSURLTypeIdentifierKey error:&error]) { 
     if ([workspace type:type conformsToType:@"public.movie"]) { 
      // the URL points to a movie; do stuff here 
     } 
    } else { 
     // handle error 
    } 
} 

(Ayrıca yerine NSWorkspace yöntemin UTTypeConformsTo() kullanabilirsiniz.)

+0

Bu iOS'ta nasıl yapıyorsun? '' '' NSWorkspace' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'AppKit'''ı gerektirir Teşekkürler. – Supertecnoboff

+0

Kendi sorumu cevabı buldu - iOS için: https://stackoverflow.com/a/5815629/1598906 – Supertecnoboff

0

Swift sürümü:

do { 
    var value: AnyObject? 
    try url.getResourceValue(&value, forKey:NSURLTypeIdentifierKey) 
    if let type = value as? String { 
     if UTTypeConformsTo(type, kUTTypeMovie) { 
     ... 
     } 
    } 
} 
catch { 
}