didReceiveScriptMessage NOT working in iOS8 WKWebView - ios8

I have such a Js injected in webView:decidePolicyForNavigationResponse:decisionHandler:
function postMyMessage()
{
try {
window.webkit.messageHandlers.SimpleBrowser.postMessage('JS for qq.com called');
} catch(err) {
alert('The native context does not exist yet ' + err);
}
}
postMyMessage()
implementing the delegate like this
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
NSLog(#"Message: %#", message.body);
}
The problem is this log only show once, never come out after, even through load another WKWebView.
I got this err msg when NOT receiving the message log.
alert The native context does not exist yet TypeError: null is not an object (evaluating 'window.webkit.messageHandlers')
Is is a bug? any solution now?

Related

How to find the tag from the error: Trying to update non-existent view with tag 85273 in React Native Android

In production of React Native app get the error on Android from crashlytics of firebase:
Fatal exception: com.facebook.react.uimanager.IllegalViewOperationException.
Trying to update non-existent view with tag 85273.
And there is no scenario of the crash, therefore it is not possible to detect it. I checked many times on emulators and a real Android device.
What did we find out about this crash?
the updateView method that caused the exception is located in node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java; 
public void updateView(int tag, String className, ReadableMap props) {
ViewManager viewManager = mViewManagers.get(className);
if (viewManager == null) {
throw new IllegalViewOperationException("Got unknown view type: " + className);
}
ReactShadowNode cssNode = mShadowNodeRegistry.getNode(tag);
if (cssNode == null) {
throw new IllegalViewOperationException("Trying to update non-existent view with tag " + tag);
}
if (props != null) {
ReactStylesDiffMap styles = new ReactStylesDiffMap(props);
cssNode.updateProperties(styles);
handleUpdateView(cssNode, className, styles);
}
}
by condition if cssNode == null, then throw an exception, it means some null came from the JS side;
ShadowNodeRegistry is a simple container class to keep track of ReactShadowNodes associated with a particular UIManagerModule instance;
and we have the number of the tag 85273, the cause of the exception.
How can I find the element in JS side by tag number 85273? Or maybe somebody could recommend me please some articles or share your experience how to solve like this crashes in Android of React Native app. Thanks in advance.

Is there any way to verify dynamic pop-up that does not appear everytime

var name = element(by.xpath("//p[contains(text(),'We will be adding this information')]"));
if ( browser.isElementPresent(name)) {
try {
element(by.xpath("//button[#class='ok-btn']")).click();
} catch (error) {
console.log('Not able to click on duplicate pop-up '+error);
}
} else {
console.log('Fresh');
}
Above code works perfectly fine in Protractor jasmine framework, if popup appears but it fails when pop-up doesn't appear and scripts execution stops there.
Popup comes only when certain condition matches.
Can you try this using the elementFinder method isPresent() instead of the browser method.
const name = element(by.xpath("//p[contains(text(),'We will be adding this information')]"));
if (name.isPresent()) {
try {
element(by.xpath("//button[#class='ok-btn']")).click();
} catch (error) {
console.log('Not able to click on duplicate pop-up '+error);
}
} else {
console.log('Fresh');
}

Swift 2.0 Errors thrown from here are not handled

Updating to 2.0 with Xcode 7 Beta 4
I have this code block
do
{
try AVAudioSession.sharedInstance().setActive(true)
} catch let err as NSError
{
println("Dim background error")
}
And its giving me the error (on the try line)
Errors thrown from here are not handled.
Is this a compiler error or is there something I am missing in my syntax?
I checked the docs and my code 'looks' correct.
What types of errors can AVAudioSession.sharedInstance().setActive(true) throw?
If it can only throw NSErrors, then there's no need of specifying this when catching the error. You could simply write:
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("Dim background error")
}
If you want to use the error in your catch-scope, you can still access it. Swift automatically binds the thrown error to error, which can be used:
catch {
// do something with `error`
}
If the method throws multiple types of errors, and you only want to deal with the ones that are NSErrors, you can conditionally bind them:
catch let specialError as NSError {
// do something with `specialError`
}
You must ensure though, that every thrown error is handled. So assuming that the method can also throw a RandomError (which I just made up now), you would have to write:
catch let randomError as RandomError {
// do something with `randomError`
}
...in addition to the catch of the NSError.
Or you could of course use the general case:
catch {
// do something with `error`
}
So I assume your problem can be solved by removing let err as NSError, from your catch-statement.
May be a compiler bug. Anyway try removing let err as NSError ; catch alone is enough if you want to catch all errors.
Also, with Swift 2 you should use print, not println.
The following code compiles without errors with XCode 7 Beta 4:
import AVFoundation
class X {
func y() {
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("Dim background error \(error)")
}
}
}
check this code that will you get idea on try/catch :
enum ErrorMessages :ErrorType {
case ErrorDescription
}
do
{
try AVAudioSession.sharedInstance().setActive(true)
} catch ErrorMessages.ErrorDescription
{
println("Present the error description here")
}

Chromecast receiver using sendLoadComplete() doesn't update status

I'm writing a Chromecast receiver to play different kind of contents (including embedded flash videos). I'd like to use my own JS library to create the player canvas, not to rely on the html video element.
I'm currently blocked because I can't get a media to be loaded using a custom behaviour :
Receiver :
Nothing fancy in the HTML, I just load my library in the #mediaWrapper div. Then I create a MediaManager from it.
var node = $( "#mediaWrapper" )[0];
var phiEngine = new phi.media.Player( node );
window.mediaManager = new cast.receiver.MediaManager( phiEngine );
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
/* Override Load method */
window.mediaManager['origOnLoad'] = window.mediaManager.onLoad;
window.mediaManager.onLoad = function (event) {
console.log('### Application Load ', event);
/* Custom code (load lib, set metadata, create canvas ...) */
window.mediaManager.sendLoadComplete(); // Doesn't seem to do anything
// window.mediaManager['origOnLoad'](event);
// -> Fails 'Load metadata error' since url is not a video stream
// -> ex: youtube url
}
/* Will never be called */
window.mediaManager['origOnMetadataLoaded'] = window.mediaManager.onMetadataLoaded;
window.mediaManager.onMetadataLoaded = function (event) {
...
}
Sender :
I use my own android application to cast to the device. I can't use the Companion library because it will be a Titanium module.
private void createMediaPlayer() {
// Create a Remote Media Player
mRemoteMediaPlayer = new RemoteMediaPlayer();
mRemoteMediaPlayer.setOnStatusUpdatedListener(
new RemoteMediaPlayer.OnStatusUpdatedListener() {
#Override
public void onStatusUpdated() {
Log.e(TAG, "onStatusUpdated");
}
}
});
mRemoteMediaPlayer.setOnMetadataUpdatedListener(
new RemoteMediaPlayer.OnMetadataUpdatedListener() {
#Override
public void onMetadataUpdated() {
Log.e(TAG, "onMetadataUpdated");
}
});
try {
Cast.CastApi.setMessageReceivedCallbacks(mApiClient,
mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
} catch (IOException e) {
Log.e(TAG, "Exception while creating media channel", e);
}
mRemoteMediaPlayer
.requestStatus(mApiClient)
.setResultCallback(
new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
#Override
public void onResult(MediaChannelResult result) {
Log.e(TAG, "Request status : ", result.toString());
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "Failed to request status.");
}
}
});
}
private void loadMedia( MediaInfo mediaInfo, Boolean autoplay ) {
try {
mRemoteMediaPlayer.load(mApiClient, mediaInfo, autoplay)
.setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
#Override
public void onResult(MediaChannelResult result) {
Log.e(TAG, "loadMedia ResultCallback reached");
if (result.getStatus().isSuccess()) {
Log.e(TAG, "Media loaded successfully");
} else {
Log.e(TAG, "Error loading Media : " + result.getStatus().getStatusCode() );
}
}
});
} catch (Exception e) {
Log.e(TAG, "Problem opening media during loading", e);
}
}
Expected behaviour :
I basically first call createMediaPlayer() once, then call loadMedia(...). The first call to loadMedia will show nothing in the log : nor success or fail. Next calls issue with errorCode 4.
I get the load event on the receiver side. But, back to the sender side, I can't manage to end the load phase and get a media session to be created.
I was expecting sendLoadComplete() to do so but I might be wrong. How can I have the media status to update and the loadMedia ResultCallback to be reached ?
My goal is to use RemoteMediaPlayer.play(), pause(), ... but for now I get stuck with 'No current media session' because the media isn't loaded yet.
Also, I'd really enjoy to be able to log any message the Sender receives, before being processed. Is it possible ?
Hope I did not forget any information,
Thanks for your help !
edit: I solved this by using a custom message channel since it seems that I can't use RemoteMediaPlayer the way I want to.
I believe the error code 4 you are receiving is bogus; see https://plus.google.com/u/0/+JimRenkel2014/posts/aY5RP7X3QhA . As noted there, I created a Chromecast issue for this (https://code.google.com/p/google-cast-sdk/issues/detail?id=305&thanks=305&ts=1403833532). Additional support for this issue will help it get fixed faster! :-)
.sendLoadComplete(true)
The boolean value helped me to receive the loaded event on sender. Might help you as well.

Alert with jqGrid error messages

I would like to get an alert when errors occur when loading my jqGrid table. For instance, when the jsonReader is not well configured, like when repeatitems is true instead of false, U can see in Firebug the error:
ccur is undefined
[Break On This Error] idr = ccur[idn] || idr;
How can I place such an error in an alert? I have already tried using loadError, but it doesn't work, because it is not even triggered.
It seems for me that you should just use try - catch block over jqGrid code:
try {
// create the grid
$("#list").jqGrid({
// all jqGrid options
});
} catch (err) {
// display the error message which you want
alert(err);
}
UPDATED: You are right, the try {...} catch (err) {...} which I described before work in IE only with reading local data. In case of getting data from the server the exception take place inside of success callback of $.ajax. To be exactly it take place inside of addJSONData or addXmlData depend of the type of data which you use. To catch the exception you should modify code of jqGrid in the place. The modified code can be about the following
success:function(data,st, xhr) {
if ($.isFunction(ts.p.beforeProcessing)) {
ts.p.beforeProcessing.call(ts, data, st, xhr);
}
try {
if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
if(lc) { lc.call(ts,data); }
if (pvis) { ts.grid.populateVisible(); }
} catch (err) {
alert(err);
}
if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
data=null;
if (npage === 1) { endReq(); }
}
I tested in the demo the corresponding modified version of jquery.jqGrid.src.js which display error message. I don't reproduced exactly the error which you described so the error message is a little other as in your case.
If you need minimized version of the modified jquery.jqGrid.src.js file you can produce it yourself with any JavaScript minimizer. For example Microsoft Ajax Minifier can be free downloaded and installed. The usage as
ajaxmin.exe jquery.jqGrid.src.js -out jquery.jqGrid.min.js
will produce the new minimized version of jquery.jqGrid.src.js which will be even a little smaller as the original jquery.jqGrid.min.js.
Another good minimizer is available online here. You should use "Simple" Optimization only.

Resources