I'm building a widget for macOS, which is target for macOS only. And, it keeps crashing after an attempt to recreate another timeline (from getTimeline function)
It throws the following error:
Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle fileDescriptor]: Invalid argument'
terminating with uncaught exception of type NSException
I believe it is generated due to the lack of implementation of the method onBackgroundURLSessionEvents(matching:_:), which brought my attention to the following documentation ⬇️
From Apple doc :
When your widget extension is active like when providing a snapshot or timeline, it can initiate background network requests. The process is similar to how an app handles this type of request, which is described in Downloading Files in the Background. Instead of resuming your app, WidgetKit activates your widget’s extension directly. To handle the result of the network request, use the onBackgroundURLSessionEvents(matching:_:) modifier to your widget’s configuration, and do the following:
Store a reference to the completion parameter. You call the completion handler after processing all network events.
Use the identifier parameter to find the URLSession object you used when initiating the background request. If your widget extension was terminated, use the identifier to recreate the URLSession.
After invoking onBackgroundURLSessionEvents(), the system calls the urlSession(_:downloadTask:didFinishDownloadingTo:) method of the URLSessionDelegate you supplied to the URLSession. When all events have been delivered, the system calls the delegate’s urlSessionDidFinishEvents(forBackgroundURLSession:) method.
To refresh your widget’s timeline after the network request completes, call the WidgetCenter methods from your delegate’s implementation of urlSessionDidFinishEvents. Once you finish handling the events, call the completion handler that you previously stored in onBackgroundURLSessionEvents().
The problem is that urlSessionDidFinishEvents(forBackgroundURLSession:) is only available for:
OS 7.0+
Mac Catalyst 13.0+
tvOS 9.0+
watchOS 2.0+
It seems like there is no equivalent idea for macOS targets. So, how should we set it up?
Related
I am building a NativeScript mobile app and among other things I am capturing for analytics purposes, I need to capture "app crashes" possibly with errors/reasons it crashed.
I came across this SO post but there it was in the response of a question on how not to let the app crash. Following was suggested to catch crash events:
var application = require("application");
application.on(application.uncaughtErrorEvent, function (args) {
if (args.android) {
// For Android applications, args.android is an NativeScriptError.
console.log("NativeScriptError: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is NativeScriptError.
console.log("NativeScriptError: " + args.ios);
}
});
If I go by the above then I have the following questions. Would appreciate if somebody can confirm if this means every-time the app is crashing it will generate this application.uncaughtErrorEvent event? Can I rely on it?
If it is true then maybe I can make a REST call to my backend and store date, time and whatever is in args.android or args.ios.
If above is not the correct way then can somebody please help me on how to go about doing this?
Any help is highly appreciated. Thank you!
The application.onUncaughtError will be hit probably 95-98% of the time during a crash; it is pretty reliable. I have seen the app crash without any notice at all it just goes poof, but I'm not sure any reporting system can handle that one.
The way I do it is during the app startup I register a couple things:
I create a global.error function; this is used for anything (like try/catch, promise/catch) that needs to send the errors through to be logged remotely. So anywhere in my codebase I can do a global.error(theError); and it will be handled; this way I do NOT have to worry about trying to load or require things while an error is taking place, as that can cause other errors.
I use the onUncaughtError event to catch anything that is not normally caught, and then notify the user that an error has occurred and quit the app. (in this case, trying to recover is not recommended as you have no idea where the error was thrown from...)
If I use a worker thread, When I startup a worker I register the worker.onerror to forward its data to the main threads global.error function AND I have a specific message from the workers' version of the global.error that sends the error back to the primary thread. This way if the worker itself calls global.error that message is passed back to the main thread and then to the global.error on the main thread which handles everything properly.
This technique allows me to catch pretty much all errors that can occur. The main global.error function and the onUncaughtError both use a simple reporting library that I built that reports all the data back to one of my servers, IF the device is online. If the device is offline, it can optionally save the data to a reporting file to be uploaded later; or just ignore it.
It also has safety checks to verify the error isn't a network error (we don't want the error reporting to go into a loop, i.e. trying to report the error causes an error, which then tries to report the error; so in the event it is a certain type of network error; it will ignore those. )
I have problem with launching Google-Cast application similar to sample CastHelloText-chrome. I slightly modified example code for my specific purposes. The goal for creating this application is to send and show image data directly in Chromecast device.
Particularly the difference between official sample and my code is in message format and its content, sent by sender application. Sender application took png image coded by base64 and send through message bus with custom namespace. Receiver application get this message and use this as data source for html object <img>.
Error appears when I do this steps:
Reload sender page, checking console if any device found.
Send the form by just pushing enter on input box (text is ignored).
Now a popup from Chromecast extension shows. Next there are two scenarios:
3a) I confirm casting to device by choosing one from the list, then I get this error message in console:
onError: {"code":"channel_error","description":"Error: Timeout","details":null}
3b) I just click somewhere else, I get this error:
onError: {"code":"cancel","description":"User closed popup menu","details":null}
Both of errors are caused by calling function chrome.cast.requestSession in chromehellotext.html at line 161, but what's really wrong I don't know.
When I step sender script I realize that function sessionListener is never called. I know that something go wrong when code try to call chrome.cast.requestSession, where described error raises. So I need help if I missed about right way to use Google-Cast API or If this problem has something to do with networking issues.
Receiver application is registered on Google Cast SDK Developer Console and I'm testing on registered device with some serial number. I'm using Google Chrome in version 42.0.2300.2 canary (64-bit) and Chrome version 40.0.2214.111 (current stable I suppose). For testing I also tried to turn off Windows Firewall entirely but with no luck.
Edit:
There were some syntactic errors that caused error message described above.
It seems like you are trying to use the data/control channel to send an image; please don't do that; that channel is not meant to be used for large data communications; in fact it cannot send anything which approaches or exceeds 64k. If your goal is to send images from your local machine, you would need to run a local web server on your local machine and serve images through the web server.
For and easiest tutorial you can have a look to this tutorial.
It is well explained in this tutorial.
Chromecast Sender application
There is no need to maintain session by yourself.
just add button and enjoy casting
mCastManager.addMediaRouterButton(mediaRoutebtn);
I found a source of my problem. There was something wrong in receiver code - syntactic and runtime errors, so I must admit that my code wasn't functional. Now its working in terms of launching application and getting session.
Unfortunate thing is that the error message generated by Chromecast extension didn't match the actual error - at least it was a bit confusing when I didn't know what's really happening on receiver side without ability to debug the code.
I started getting a weird error in my project, so I created a whole new document-based project just to test (in Xcode 4). I added a 'Text View' to the Document.xib, and ran the program. I manage to open a few new documents, type some stuff in the text view, then I pause, and then the program terminates. It gives me: "Program received signal "SIGABRT".
The error is in the default document.m file, in method:
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
on line:
#throw exception
What's going on?
PS. I looked at the Activity Monitor, and all the loads: System Load, User Load, go way up all at once before it quits.
From the docs:
The default implementation of this method throws an exception because
at least one of the writing methods (this method,
writeToURL:ofType:error:, fileWrapperOfType:error:, or
writeToURL:ofType:forSaveOperation:originalContentsURL:error:) must be
overridden.
My guess is that you didn't implement these method(s). I also bet you're on Lion and have autosaving enabled (see +autosavesInPlace), and that the exception is thrown when the app tries to autosave after an internal timer / change watcher is triggered.
I'm trying to catch unhandled exceptions in the application and restart it on them using WaitForDebugEvent function. But I can't tell when exception is handled by application (try..catch for example) and when is not. How do I do that? There seem to be no such data in DEBUG_EVENT structure.
If your not catching certain exceptions using WaitForDebugEvent, you might want to try injecting an UnhandledExceptionFilter as well. other than that, check that your processing matches Microsofts Example
In the EXCEPTION_DEBUG_INFO structure, which is in the DEBUG_EVENT structure, there is a field dwFirstChance:
If the dwFirstChance member is nonzero, this is the first time the debugger has encountered the exception. Debuggers typically handle breakpoint and single-step exceptions when they are first encountered. If this member is zero, the debugger has previously encountered the exception. This occurs only if, during the search for structured exception handlers, either no handler was found or the exception was continued.
So you will want to look for times where dwFirstChance is 0.
But if you just want to restart your app when it fails, it might be easier to create another app to watch for the failure of the first one, rather than using the Windows debugging api.
Is there a way of catching exceptions (particularly for network errors
/ no connection available) when using a MPMoviePlayerController?
I am particularly concerned that once an instance of the player is initialised with initWithURL: you have no way of knowing whether the movie load has failed for some reason.
I have reviewed the available documentation and realise I can get a
notification for loadState changes through
moviePlayerLoadStateChanged:(NSNotification*)notification.
Problem is the loadState constants available don't cater for error handling:
MPMovieLoadStateUnknown
MPMovieLoadStatePlayable
MPMovieLoadStatePlaythroughOK
MPMovieLoadStateStalled
(in case you are wondering, MPMovieLoadStateStalled this doesn't get called during network errors for some reason?)
There's a deprecated MPMoviePlayerContentPreloadDidFinishNotification that provides a userInfo dictionary with an "error" key but nothing for iOS 3.2 and above.
Any help would be very much appreciated.
In the end I got this sorted by subscribing to MPMoviePlayerPlaybackDidFinishNotification and watching for MPMovieFinishReasonPlaybackError.
More details here https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006953-CH3-SW17