0

I'm developing iOS Keyboard Extension, and I load some data of keyboards from plist file. My version is iOS 8.4/Xcode 6.4.

But sometimes(not everytime), when in viewdidload of InputViewController, NSDictionary(contentsOfFile:) returns nil. It appears when I switched between my keyboard and another one frequently.

What I checked:

  • the file is not nil.
  • the file name doesnt change at all.
  • try again while it is nil.
  • contentsOfUrl instead of filepath.
  • there are only ascii codes in plist file.

What I'm suspecting:

  • file-io problems when the process doesnt end properly.
  • swift problems

Thanks to Aderstedt, I checked NSError.

let nsdata = NSData(contentsOfFile: file, options: nil, error: &nserror)
if nserror != nil {
    NSLog("load error: \(nserror?.description)")
}

load error: Optional("Error Domain=NSCocoaErrorDomain Code=256 \"The operation couldn\U2019t be completed. (NSCocoaErrorDomain error 256.)\" UserInfo=0x17066c700 {NSFilePath=/private/var/mobile/Containers/Bundle/Application/"My Application", NSUnderlyingError=0x174845df0 \"The operation couldn\U2019t be completed. (NSPOSIXErrorDomain error 24 - Too many open files)\"}")

I fixed this with closing other closing garbage files, and following link was also helpful.

on iOS/iPhone: "Too many open files": need to list open files (like lsof)

Community
  • 1
  • 1
Jeonghan Joo
  • 225
  • 2
  • 10
  • Please share your code snippet where you are facing this problem. – iYoung Jul 08 '15 at 05:48
  • 1
    To see what the problem is, try first loading the contents of the file into an `NSData` object. This lets you pass an `NSErrorPointer` which you can use to see why the file cannot be loaded. – Aderstedt Jul 08 '15 at 07:00
  • @RajatDeepSingh I thought unless I upload whole project, just snippet is not important to this question. If I could make the problem more clear, I would share it. Sorry. It was just to load NSDictionary from Plist resource file. – Jeonghan Joo Jul 08 '15 at 09:43
  • @Aderstedt I will try it. Thanks! – Jeonghan Joo Jul 08 '15 at 09:44
  • The problem is absolutely clear. You have too many open files. Could it be that you are opening lots of files and not closing them? The problem is not with the call to contentOfFile: If you are worried about writing files while your app crashes, use atomic versions. – gnasher729 Jul 08 '15 at 10:37
  • @gnasher729 yes, thanks to Aderstedt's way to see the error code, I can see it's kinda file-open/close problems. I will check! thank you also. – Jeonghan Joo Jul 09 '15 at 02:39

0 Answers0