Working with webinpectord - ios

I just want to communicate with Mobile Safari using 'webinpectord' (hobby project). My aim is to just display an alert 'hi' on Mobile Safari. I know I can do this using Safari's debugging console. At the moment what things I know is Mobile Safari ('webinpectord') listen to port 27753 on localhost using IPV6 protocol. And from this page I understand the sequense of communication with Mobile Safari. I perused already working programs like remote-debug, node-iosdriver and iOS-webkitproxy. Then I tried to write a program in C which connects to localhost:27753 and then send and receive commands. My problem is I can connect and send commands to port 27753 but not getting any response from that port.
I tried to send
{ __argument: { WIRConnectionIdentifierKey: '17858421-36EF-4752-89F7-7A13ED5782C5' },
__selector: '_rpc_reportIdentifier:' }
According to this article, Mobile Safari has to send back response like
{ __selector: '_rpc_reportSetup:',
__argument:
{ WIRSimulatorNameKey: 'iPhone Simulator',
WIRSimulatorBuildKey: '10A403' } }
{ __selector: '_rpc_reportConnectedApplicationList:',
__argument:
{ WIRApplicationDictionaryKey:
{ 'com.apple.mobilesafari':
{ WIRApplicationIdentifierKey: 'com.apple.mobilesafari',
WIRApplicationNameKey: 'Safari',
WIRIsApplicationProxyKey: false } } } }
but I am not getting any response from Mobile Safari. I just can send commands to there.
Let us assume that my program is buggy !
So I tried to experiment with 'telnet'. Here also I can connect to localhost:27753 and I can send commands and not getting any response. I am attaching screen shot.
You can see that I tried many combinations like
{ "__argument": { "WIRConnectionIdentifierKey": "17858421-36EF-4752-89F7-7A13ED5782C5" }, "__selector": "_rpc_reportIdentifier: " }
{\"__argument\": { \"WIRConnectionIdentifierKey\": \"17858421-36EF-4752-89F7-7A13ED5782C5\" }, \"__selector\": \"_rpc_reportIdentifier: \"}
"{ "__argument": { "WIRConnectionIdentifierKey": "17858421-36EF-4752-89F7-7A13ED5782C5" }, "__selector": "_rpc_reportIdentifier: " }"
but nothing worked.
Lastly I tried curl to send data. That also failed !
Can anybody tell me what should I do to get response like
{ __selector: '_rpc_reportSetup:',
__argument:
{ WIRSimulatorNameKey: 'iPhone Simulator',
WIRSimulatorBuildKey: '10A403' } }
{ __selector: '_rpc_reportConnectedApplicationList:',
__argument:
{ WIRApplicationDictionaryKey:
{ 'com.apple.mobilesafari':
{ WIRApplicationIdentifierKey: 'com.apple.mobilesafari',
WIRApplicationNameKey: 'Safari',
WIRIsApplicationProxyKey: false } } } }
when sending request
{ __argument: { WIRConnectionIdentifierKey: '17858421-36EF-4752-89F7-7A13ED5782C5' },
__selector: '_rpc_reportIdentifier:' }
to localhost:27753 using 'telnet' or 'curl'.
I tried two days in different ways (wrote C program, python program and lastly tried telnet and curl) and did not get succeeded. So please help !

Mobile Safari use customized binary protocol(binary property list, see bplist-creator) to communicate with Safari debugging mode.
The correct format for this JSON command should be this:
{"__argument":{"WIRConnectionIdentifierKey":"990cc163-d8b2-4d22-8d1c-644e100a5a07"},"__selector":"_rpc_reportIdentifier:"}
Notice that every "key" should be double quoted.
You can refer the appium for details.

Related

How to get HTTP status code of a page opened in a webview in Electron

I want to open a remote web app in electron's webview, but this app is sometimes down and return 503 response. The problem is that I can't detect any HTTP errors from electron, so that I can do something about it from my side.
Here is a sample of my code :
webviewObj = document.createElement('webview');
webviewObj.addEventListener('did-fail-load', (e) => {
// Is not fired for HTTP errors
});
webviewObj.addEventListener('did-finish-load', (e) => {
// No info about HTTP status code
});
webviewObj.src = "https://web-app.com";
In an old version of electron, the webview had an event did-get-response-details that gives httpResponseCode, but it got deprecated, and I could not find an alternative.
Thanks for your help.
you can use this API https://www.electronjs.org/docs/api/web-contents#event-did-navigate
win.webContents.on('did-navigate', (_event: any, _url: string, httpResponseCode: number) => {
if (httpResponseCode >= 400) {
// what you want to do
}
});

ionic framework bad request when calling web service over 3G

I'm developing iOS app using ionic framework and I have one problem when I try to call web service by using 3G network.
here is my service in UserService:
function getUserStat(user_id){
var request = $http({ method: "get",
url: "http://www.example.com/user.php",
params: {
action: "stat",
user_id:user_id
},
data: {
}
});
return(request.then(handleSuccess, handleError));
}
function handleError( response ) {
// The API response from the server should be returned in a
// nomralized format. However, if the request was not handled by the
// server (or what not handles properly - ex. server error), then we
// may have to normalize it on our end, as best we can.
if (!angular.isObject( response.data ) || !response.data.message) {
return( $q.reject("An unknown error occurred.") );
}
// Otherwise, use expected error message.
return( $q.reject( response.data.message ) );
}
// I transform the successful response, unwrapping the application data
// from the API response payload.
function handleSuccess( response ) {
return( response.data );
}
the getUserStat() function will return json back.
here is my controller
UserService.getUserStat($scope.user_id).then(function(data){
alert("Result: " + JSON.stringify(data));
});
in my control I just show the json.
I build this code to my iPhone and test it over WIFI network, everything work fine. If i update the serverside, UserService.getUserStat in controller will show update. but the problem is when I test it on 3G network, iPhone always show the old json returned from the server (even I change server side data).
any idea to solve this problem?
Thank you
I had a similar problem when I tried to upload a camera photo to my data server.when i tested the app on my local WIFI it worked perfectly but when I tested it outside i noticed it fails to upload the file. eventualy the problem was that since the internet outside is much slower the app moved to another view without finish the upload action.
so for example if your controller looks something like this:
.controller('Ctrl1', function(webService, $scope, $state) {
UserService.getUserStat($scope.user_id).then(function(data){
alert("Result: " + JSON.stringify(data));
});
$state.go('app.posts');
});
it should be like this:
.controller('Ctrl1', function(webService, $scope, $state) {
UserService.getUserStat($scope.user_id).then(function(data){
alert("Result: " + JSON.stringify(data));
})
.finally(function() {
$state.go('app.posts');
});
});

Azure Mobile Services Push not working

I am trying to implement push to my app.
I've followed this guide:
http://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-ios-get-started-push/
However, I am using API's instead of the Data-scripts, so in one of my API methods I am doing this:
var push = request.service.push;
push.apns.send(null, {
alert: "Alert",
payload: {
inAppMessage: "Hey, a new item arrived"
}
}, {
success: function(resp) {
console.log(resp)
},
error: function(err) {
console.error(err)
}
});
My log is showing this (So I land in the success-method [Also I know that I should never land in error for iOS due to apples push server not responding with error]):
{ isSuccessful: true,
statusCode: 201,
body: '',
headers:
{ 'transfer-encoding': 'chunked',
'content-type': 'application/xml; charset=utf-8',
server: 'Microsoft-HTTPAPI/2.0',
date: 'Mon, 20 Oct 2014 11:31:21 GMT' },
md5: undefined }
My app is registered correctly like this, I see the callback message and no error:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken: (NSData *)deviceToken
{
[client.push registerNativeWithDeviceToken:deviceToken tags:#[#"uniqueTag"] completion:^(NSError *error)
{
NSLog(#"registerNativeWithDeviceToken callback");
if (error != nil)
{
NSLog(#"Error registering for notifications: %#", error);
}
}];
}
But no push message land in my iphone! Nothing is happening.
Im trying to check for errors in my Notification Hub but I see no log there.
What am I missing? I really don't get it where my actual device id is stored server side anyway. I must be missing something.
Thank you!
The best way to debug what is occurring is to follow the Notification Hub debugging steps here: http://msdn.microsoft.com/en-us/library/azure/dn530751.aspx
I would begin by using Service Bus Explorer to double-check the registration has the device token and tags you expect. After verifying that, please test sending an alert directly via the Notification Hub portal. If you still have issues, please send me an email at toddreif#microsoft.com.
Use your debug menu in Azure as #Todd Reifsteck said, and please test the tag name both "myTag" and myTag while debugging.

Internet check is failure in Iphone

In my sencha touch application i am unable to retrieve internet connection, but device able to access the wifi when i try to surf through browser. In android its working fine, but in ios the connection is undefined. I am using same wifi for both devices.
checkConnection: function() {
if (Ext.os.is('android') || Ext.os.is('iphone')) {
alert("connection"+Ext.device.Connection.isOnline());
alert('Your connection type is: ' + Ext.device.Connection.getType());
return Ext.device.Connection.isOnline();
}
Are you using phonegap/cordova? If so then why don't you use the cordova network API directly? I.e. try something like
checkConnection: function() {
if (Ext.device) {
return Ext.device.Connection.isOnline();
} else {
return navigator.network.connection.type != Connection.NONE;
}
return false;
}

Adobe PhoneGap Build (iOS) and PushWoosh

According to the docs at PushWhoosh:
http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/
I should be able to use Adobe's Build cloud service to build PhoneGap apps. I've followed the instructions in the docs, but can't get my app to register with the PushWhoosh service (i.e.: it's not sending a device token).
I think the issue has to do with the registration of the plugin in config.xml. According to the Adobe Build docs, the only push plugin supported is their "GenericPush", which I've added to my config.xml file like so:
I've also whitelisted the pushwhoosh.com domain.
In my index.html file, I have the function initPushwhoosh, which gets called when the device is ready:
function initPushwoosh() {
try {
var pushNotification;
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(successHandler, errorHandler, { "senderID": "replace_with_sender_id", "ecb": "onNotificationGCM" });
}
else {
pushNotification.register(tokenHandler, errorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" });
}
}
catch (err) {
alert(err.message + "\n\n" + err.name);
}
}
And my tokenHandler function (I'm building for iOS) looks like:
function tokenHandler(result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
PushWoosh.appCode = "E0313-D27FA";
PushWoosh.register(result, function (data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function (errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
Through debugging, it looks like the "pushNotification.register" function never gets called, and the try/catch statement doesn't display any error messages. That function is:
// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android)
PushNotification.prototype.register = function (successCallback, errorCallback, options) {
alert("about to register");
if (errorCallback == null) { errorCallback = function () { } }
if (typeof errorCallback != "function") {
alert("PushNotification.register failure: failure parameter not a function");
return;
}
if (typeof successCallback != "function") {
alert("PushNotification.register failure: success callback parameter must be a function");
return;
}
cordova.exec(successCallback, errorCallback, "GenericPush", "register", [options]);
};
My thinking is that it has to do with the plugin declaration (<gap:plugin name="GenericPush" />) in config.xml; I've tried changing it to (based on some other sample code I found):
<gap:plugin name="PushPlugin"/>
But that didn't work either. Note: when I did this, I tried changing:
cordova.exec(successCallback, errorCallback, "GenericPush", "register", [options]);
to
cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]);
The complete code can be found here:
https://github.com/appburnr/PushWhooshTest
I've tripled-checked the my PushWhoosh AppID is correct, but I can never get the app to appear as registered device in my PushWhoosh control panel.
Any ideas?
Are you sure this code is correct?
pushNotification.register(successHandler, errorHandler, { "senderID": "replace_with_sender_id", "ecb": "onNotificationGCM" });
Shouldn't it be the Project ID from GCM? It might explain why the device doesn't register for push notifications.
I'm not familiar with PushWoosh, but they do have a guide to how to achieve this with Build here:
http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/
Have you followed each step?
If you still haven't had success (I hope you have) try this guide:
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
I've built a solution using push notifications myself now, and found my biggest issue was that I hadn't set up the certificates. This guide is perfect.
ALSO remember that push notifications won't work in the emulator, only on a real device.

Resources