AVAudioPlayer initialization: error code -50 - iphone

I recently ran into a problem that I couldn't find discussed anywhere on the internet - I was initializing an AVAudioPlayer to play an audio file, and getting the following error:
Error Domain=NSOSStatusErrorDomain Code=-50 "Operation could not be completed. (OSStatus error -50.)
As it turns out, I had made a mistake creating my NSURL to send to the audio player init method, resulting in the NSURL object being null. Stupid mistake, pretty easy to find when debugging, but I thought I'd list it here just in case someone else does the same thing.

“ OSStatus error -50” means paramErr, an old-style Mac error code indicating a bad parameter.

Regarding the comment from Brynjar:
The Apple NSURL Class Reference describing URLWithString states
To create NSURL objects for file system paths, use
fileURLWithPath:isDirectory: instead.
I have found that using URLWithString for file system paths generates the error reported by pix0r and therefore could be another explanation for error code = -50

Make sure your NSURL is valid, or you will get error code -50 "Operation could not be completed".

I'm adding my version of the issue and solution because I encountered the error with a print statement. I think it was related to string interpolation and or trying to forcibly print nsattributedstrings. I attempted to do the following.
print("THE ARRAY COUNT IS : \(unwrappedResults.count)\n\n\n
THE FULL ARRAY IS THE FIRST WHOLE RESULT IS: \(unwrappedResults)\n\n\n \ (unwrappedResults[0])\n
THE ATTRIBUTED FULL TEXT IS: \(unwrappedResults[0].attributedFullText)\n\n\n
THE ATTRIBUTED PRIMARY TEXT IS: \(unwrappedResults[0].attributedPrimaryText)\n\n\n
THE ATTRIBUTED SECONDARY TEXT IS: \(unwrappedResults[0].attributedSecondaryText)\n\n\n")
something about this was incorrect and no print would occur. I would receive the error following errors in my console.
boringssl_metrics_log_metric_block_invoke(131) Failed to log metrics
&
boringssl_metrics_log_metric_block_invoke(133) Error Domain=NSOSStatusErrorDomain Code=-50 "Unsupported xpc type"
UserInfo={NSDescription=Unsupported xpc type}
I fixed this issue by changing the way I unwrapped/the variables values. Fundamentally I think I was trying to print something using string interpolation that could not be printed and that is what caused this error.

Related

WKRefreshBackgroundTask cleanupStorage Error attempting to reach file

Whats this error I get when making a URLBGTask in WatchOS4 on the Simulator?
2017-09-28 16:05:26.452999+0900 MiFollowers WatchKit Extension[4628:4012814] [bg_app_refresh] -[WKRefreshBackgroundTask cleanupStorage]_block_invoke:213: Error attempting to reach file:///Users/ryuuzaki/Library/Developer/CoreSimulator/Devices/2E4D6389-93B7-4542-B07F-9A02C720B9AF/data/Containers/Data/PluginKitPlugin/FA4415DF-D984-4394-80B9-EDA199AB587E/Library/com.apple.watchkit/bktaskapp_(null): Error Domain=NSCocoaErrorDomain Code=260 "The file “bktaskapp_(null)” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///Users/ryuuzaki/Library/Developer/CoreSimulator/Devices/2E4D6389-93B7-4542-B07F-9A02C720B9AF/data/Containers/Data/PluginKitPlugin/FA4415DF-D984-4394-80B9-EDA199AB587E/Library/com.apple.watchkit/bktaskapp_(null), NSFilePath=/Users/ryuuzaki/Library/Developer/CoreSimulator/Devices/2E4D6389-93B7-4542-B07F-9A02C720B9AF/data/Containers/Data/PluginKitPlugin/FA4415DF-D984-4394-80B9-EDA199AB587E/Library/com.apple.watchkit/bktaskapp_(null), NSUnderlyingError=0x79b0e340 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Any of you bright minds out there know what all this means?
I was getting this too. Drove me nuts for the last two days.
I'm still not sure if it is a bug or "feature" to require you to use the userInfo property. This is happening if you don't get the userInfo property from the background refresh task in the handle(_ backgroundTasks) method. Any access of the property works. A simple workaround one to get rid of the error is to schedule your next background refresh in the handle method with backgroundTask.userInfo in the userInfo: parameter which just keeps assigning nil to the next task.
WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: refreshDate, userInfo: backgroundTask.userInfo) { (error) in
if let error = error {
print ("Background task error:\(error.localizedDescription)")
}
}
Of course this workaround means you won't be able to use userInfo. Better code might be to stick something in there such as the scheduling date or an identifier for the task, or a dictionary of [String:Any] for both.

Is there a list of MPMoviePlayer error codes

if a movie finishes with an error, then I might get an error like:
Error Domain=MediaPlayerErrorDomain Code=-12847 "This movie format is
not supported."
The same description is used for different error codes - but I can't find the code definitions anywhere.
Are they available?
Here you go. https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVFoundation_ErrorConstants/Reference/reference.html
God help you if your code (like mine) was -11800 (AVErrorUnknown).

iPhone - NSError reference : constants and code

I'm searching some precise doc where I can associate an error number to its constant. Let's say, for example, I'm searching the constant of NSError.code = 102. How may I do to find it ? Searching the Web does not help. Searching the headers file is a headache.
How would you do this ?
you can find some of refrences here for NSError
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/Reference/Reference.html
you can found some of error detail here
http://www.lifeasbob.com/Code/ErrorCodes.aspx
The code should belong to the domain of NSError, check the documentation for the associated error domain and you should find the correct code. The domain is also a good hint of which headers to search if documentation is unavailable. Apple does list the Foundation Constants.
It's WebKitErrorDomain - WebKitErrorFrameLoadInterruptedByPolicyChange
Frame load interrupted error while loading a word document in UIWebView
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Miscellaneous/WebKit_Constants/#//apple_ref/doc/constant_group/WebKit_Policy_Errors

NSURL Exceptions

I am trying to grab a path value from an array for an NSURL to set an icon in my app. I get an
NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x5622590.
If I use an nslog I get the expected output:
NSLog(#"%#",[[wforecast.wicons objectAtIndex:0]valueForKey:#"nodeContent"]);
Which gives me:
Im setting the value as follows
NSURL *urlpath;
NSString *urls = [[wforecast.wicons objectAtIndex:0] valueForKey:#"nodeContent"];
urlpath = [NSURL URLWithString:(NSString *)urls];
I appreciate this is a longwinded way of doing things but I was trying to break up the individual components to find out what was going wrong but I am at a loss!
You have essentially the same problem as this other questioner had. You passed an object that is not an NSString where you needed to pass an NSString.
Use the debugger to determine exactly where the exception occurred. If you haven't done this, I wouldn't be so sure that the code you showed is what caused it; the debugger will tell you where the exception occurred with no room for doubt.
Once you've found where the exception occurred, you can examine the object that you passed, and look back at where you got it from. You need to fix either how you retrieve the string or how you stored it in the place you're now getting it from.

iPhone Objective-C JSON Parser

Has anyone had issues with a size limit on a returned JSON Object using the JSON Parser that is available for the iPhone?
I am using this open-source JSON Framework (I am using the latest version)
If I reduce the size of the returned JSON my app will run just fine. If the object gets too large, the app crashes with the below error:
-JSONValue failed. Error trace is: (
Error Domain=org.brautaset.JSON.ErrorDomain Code=3 UserInfo=0x4141580 "Unrecognised leading character"
Don't be fooled though... it has nothing to do a leading character except that it seems to split the JSON at a certain size and then ends up with a random leading character because the next JSON string starts with a random character.
Looks like I was wrong. I was trying to parse the JSON in a didReceiveData callback method, which gets called multiple times as data is received. I needed to concatenate the result as it came in and then parse the JSON in connectionDidFinishLoading.
Thanks for looking.