2011-08-16 1 views
0

내 iOS 앱에서 iTunes를 통해 일부 jpg 파일을 다운로드 할 수 있기를 바랍니다. 그래서 UIFileSharingEnabled를 활성화했습니다. 그러나 사용자는 이제 내 앱에 파일을 넣을 수 있습니다. 나는 그것을 막고 싶다. 그렇게 할 수있는 방법이 있습니까?UIFileSharingEnabled 파일 저장

감사합니다.

답변

1

차단할 수 있다고 생각하지 않지만 앱이 활성화되면 원치 않는 파일을 삭제할 수 있습니다.

아래 샘플처럼 약간의 코드를 입력하십시오. iTunes에서 사용할 수 있도록 파일을 삭제하지 않으려면 테스트를 작성하십시오.

응용 프로그램 대리인의 applicationDidBecomeActive :에서 호출하십시오.

더 신중한 경우 사용자가 거기에 주차 한 것과 동일한 이름의 jpg 파일을 떨어 뜨리지 않았는지 확인하고 싶을 수 있습니다. 당신은 날짜의 동일성 또는 그 중 일부를 테스트 할 수 있습니다. 많은 파일이 없다면 모든 것이 삭제되고 앱이 활성화되면 다시 쓸 수 있습니다.

- (void) removeUnwantedFiles; 
{  
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSArray* directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:inboxPath error:NULL]; 

    if (!directoryContents || [directoryContents count] == 0) 
    { 
     return; 
    } 

    for (NSString* fileName in directoryContents) 
    { 
     if (/* some test of filename to see if it's one of my kosher files */) continue; 

     NSString* filePath = [documentsDirectory stringByAppendingPathComponent:fileName]; 
     NSError* error = nil; 
     BOOL success = [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; 
     // NSLog(@"Deleting (%@): %@", success ? @"succeeded" : @"failed", [filePath lastPathComponent]); 
     if (!success) 
     { 
      NSLog(@"Error: %@", [error localizedDescription]); 
     } 
    } 
} 
+0

여러분의 조언에 감사드립니다. :) – Pierre