thanks for your message, I gave a try and I am stuck on that.
I tested several options. We cannot postpone the deallocation inside the dealloc itself.
So I added a callback "readyToRemoveVideoPlayer" and from where we can destroy our sdk and do the deallocation at all stages.
In the console logs, I can see the deallocation in progress after adding several NSLog.
However, when the process is complete and if I deallocate the adsLoader and the parent class embedding the Google IMA logic, I get the following crash at adsLoader.adsLoadedWithData :
#1 0x000000010b1df109 in -[IMAAdsLoader handleMessageAdsLoaded:] ()
#2 0x000000010ea6b54c in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
#3 0x000000010e969a04 in _CFXNotificationPost ()
#4 0x000000010bf46968 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#5 0x000000010b1dc317 in -[IMAJavascriptSession didReceiveMessage:] ()
#6 0x000000010b1db6b0 in -[IMAJavascriptDispatcher processNewMessage:] ()
#7 0x000000010b1db20e in -[IMAJavascriptDispatcher processNewMessageWithChannelName:data:] ()
#8 0x000000010b1dad2e in -[IMAJavascriptBridge userContentController:didReceiveScriptMessage:] ()
#9 0x000000010b53d79e in ScriptMessageHandlerDelegate::didPostMessage(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, WebCore::SerializedScriptValue&) ()
in my code I am doing the following:
- (void)adsLoader:(IMAAdsLoader *)loader adsLoadedWithData:(IMAAdsLoadedData *)adsLoadedData
{
NSLog(@"Ad Loaded ads : %@", adsLoadedData.description);
[_timeOutHandler invalidate];
_timeOutHandler = nil;
_adLoaded = YES;
if (self.sdk.isShuttingDown) {
self.adsLoader.delegate = nil;
_adRequestInProgress = NO;
[self.apiProxy readyToRemoveVideoPlayer];
return;
}
...
1/ Without a clean solution to stop any network operations inside the IMA component, it will be difficult to remove the IMA instance safely.
The sdk we built could be destroyed at any time.
The crash still happens when we remove IMA at early stage after the Ad request was just sent.
So even after getting the response, it seems to be too soon to deallocate at this time.
What can I do? Any quick workaround on this?
In our project, we had to manage data downloading in a safer way to be able to cancel any operation in progress.
So with NSOperationQueue and URLConnection, you can cancel a request.
2/ As you can see from this piece of code, I also managed a timeout for the Ad request as there's no timeout mechanism built-in. (Correct me if I am wrong)
Maybe such thing could be a good addition on a next build ?
Thanks.
Regards
Frédéric Beléteau
Media Development Team
Akamai Technologies