title: Why am I able to access file when device is locked? (iOS)
body: <p>My app has turned on Data Protection and I created a file with <code>NSFileProtectionComplete</code></p>
  
  <pre><code>+ (void)createLogFile {
      NSString *deviceModel = [Utils getDeviceModel];
      NSString *appVersion = [Utils getAppVersion];
      NSData *initData = [[NSString stringWithFormat:@"%@-%@\n================================\n\n\n", deviceModel, appVersion] dataUsingEncoding:NSUTF8StringEncoding];
     [[NSFileManager defaultManager] createFileAtPath:[self logFilePath]
                                          contents:initData
                                        attributes:@{NSFileProtectionKey: NSFileProtectionComplete}];
  }
  </code></pre>
  
  <p>and when I lock my device <code>applicationProtectedDataWillBecomeUnavailable:</code> will be called.</p>
  
  <pre><code>- (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application {
      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
          NSData *key = [MyKeychain getKey];
          NSString *log = [NSString stringWithFormat:@"The key is:\n %@", key];
          [MyFileLogger logInfo:log];
      });
  }
  </code></pre>
  
  <p>Then I can find the result in the file, which means I was able to write that file when my device is locked.
  Shouldn't Data Protection prevents from accessing files when device is locked? What's wrong?</p>
  
  <p>--updated-- (add method logInfo:)</p>
  
  <pre><code>+ (void)logInfo:(NSString *)str {
      NSString *info = [self wrapWithTimestamp: str];
      NSString *logFilePath = [Utils logFilePath];
      if (![[NSFileManager defaultManager] fileExistsAtPath:logFilePath]) {
          [Utils createLogFile];
      }
      NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:logFilePath];
      [handle truncateFileAtOffset:[handle seekToEndOfFile]];
      [handle writeData:[info dataUsingEncoding:NSUTF8StringEncoding]];
      [handle closeFile];
  }
  </code></pre>