Internet check is failure in Iphone - ios

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;
}

Related

Flutter Blue Writing Automatically

I have used Flutter Blue for a college work, where I need to create an application to fetch and pass information to an equipment. The passing of this data must be automatic, as in any application (after all the end user should not look for the services and characteristics necessary to carry out the process). The problem is that I am not being able to perform the data passing soon after connecting with the device.
I'm using the App example I downloaded at https://github.com/pauldemarco/flutter_blue, so the basic idea is that as soon as I connect to my bluetooth device I send a message to a certain device. There is already an answered question that has the interest of setting notifications when connecting at Flutter Blue Setting Notifications
I followed the same example but instead of using _setNotification (c) I used the _writeCharacteristic (c), but it does not work.
_connect(BluetoothDevice d) async {
device = d;
// Connect to device
deviceConnection = _flutterBlue
.connect(device, timeout: const Duration(seconds: 4))
.listen(
null,
onDone: _disconnect,
);
// Update the connection state immediately
device.state.then((s) {
setState(() {
deviceState = s;
});
});
// Subscribe to connection changes
deviceStateSubscription = device.onStateChanged().listen((s) {
setState(() {
deviceState = s;
});
if (s == BluetoothDeviceState.connected) {
device.discoverServices().then((s) {
services = s;
for(BluetoothService service in services) {
for(BluetoothCharacteristic c in service.characteristics) {
if(c.uuid == new Guid("06d1e5e7-79ad-4a71-8faa-373789f7d93c")) {
_writeCharacteristic(c);
} else {
print("Nope");
}
}
}
setState(() {
services = s;
});
});
}
});
}
I have changed the original code so that it prints me the notifications as soon as I perform the writing method. The notifications should show me a standard message that is in the firmware of the device, but instead it is printing me the Local Name of the bluetooth chip, being that if I select the service and characteristic manually the return is the correct message.
You'd need to elaborate how you're executing writes on the descriptor - inside _writeCharacteristic(c).
BluetoothDescriptor.write() is a Future per docs, you should be able to catch any errors thrown during write.

Potential causes of Ionic function not working in Ionic View, but working on web

I am building a food delivery app using Ionic. And I am having problems getting the app to work on mobile for the address creation step. After creating an account the user must create a delivery address, at which point the app figures out what delivery location to use.
Address creation works in Chrome (ionic serve) and in iOS simulator (ionic run ios -l -c -s).
However, once I've uploaded the app to my Ionic View iOS app for testing, it gets stuck at the Address creation step.
But at the address creation step, the Ionic loading wheel starts but it doesn't go away and there is no state transition to the menu.
Here is the implementation in the controller.
Address.create($scope.newAddress, $scope.user)
.then(function(response) { // never gets a response back in Ionic View
console.log("address created");
user.save(null,
{ success: function(user) {
// success callback
}, error: function(error) {
// throw error
}
});
}, function(error) {
// throw error
});
The Address.create() method I have implemented is fairly lengthy:
...
.factory('Address', ['$http', '$q', 'PARSE_HEADERS'
function ($http, $q, PARSE_HEADERS) {
return {
create: function(data, userID) {
var deferred = $q.defer();
var zipArray = ['1111','22222','33333'];
var inZone = false;
var restaurantCoords = {
latitude: 11.11111, longitude: 22.22222
};
for (var i=0, bLen=zipBrooklyn.length; i<bLen; i++) {
if(data.zipCode==zipArray[i]) {
inZone = true;
}
}
if (inZone == true ) { // valid zip
function onSuccess(coords) {
var limit = 3041.66;
var meters = getDistance(coords, restaurantCoords);
if (meters < limit) {
$http.post('https://api.parse.com/1/classes/Address', data, {
headers: PARSE_HEADERS
})
.success(function(addressData) {
deferred.resolve(addressData);
})
.error(function(error, addressData) {
deferred.reject(error);
});
}
function onError() {
deferred.reject("Unable to Geocode the coordinates");
}
// GET COORDS
navigator.geocoder.geocodeString(onSuccess, onError, data.address1 + ',' + data.zipCode);
}
}
return deferred.promise;
}]);
I've stripped out all of the code that I believe was working.
So a valid answer for this question could take multiple forms:
I'd accept an answer giving a decent way to debug apps IN Ionic View.
Or, if someone could provide an answer as to why it might be working in the browser and in iOS Simulator, but not iOS itself, that would be appreciated even more.
Ionic view doesn't support all the plugins yet. please take a look at this link for the list of supported plugins.
Device is always better (First Option). If you have a ios device and apple developer account. You can create and configure the required certificate with the device id and run the app using 'ionic run ios'. Second option is iOS simulator. You can use the simulator for your whole app, though few tasks would need a device.
Even if you use the simulator for the whole development, it is always advisable to test in the device before launcing the app.

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');
});
});

Working with webinpectord

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.

UDP Send Error on BlackBerry

I am writing network application for Blackberry. This code is correct on the simulator but not working on a device. When I run my application on the simulator, my server recieves the message but when I run it on a device, I get an Exception, not IOException, with message "NULL".
try {
byte[] b = msg.getBytes();
dc = (UDPDatagramConnection)Connector.open("datagram://"+getHIP()+":" + getHPort());
Datagram dobject = dc.newDatagram(b, b.length);
dc.send(dobject);
System.out.println("Addr:" + dobject.getAddress());
System.out.println("Well Done!");
} catch (IOException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (dc != null) {
try {
dc.close();
} catch (Exception f) {
System.out.println("Failed to close Connector: " + f);
}
}
}
Network access on the BlackBerry is far from seemless from a developer's point of view. You either have to specify how the connection should be made in the URL, or the device has to have the correct APN settings in Options > Advanced Options > TCP Settings. You could try finding those and entering them to see if it works.
UDP requires the APN to be set in the Connector.open():
(DatagramConnection) Connector.open("udp://<host>:<dest_port>[;<src_port>]/<apn>[|<type>][;tunnelauthusername=<apn username>;tunnelauthpassword=<apn password>]");
For more info on that check out the Connector
It works fine on the simulator w/o APN because the simulator doesn't have an APN, but you need on a real device.
I can think of two possibilities:
UDP is optional in the J2ME spec - so maybe the Blackberry doesn't support it.
The network the device is on might not support it, and the device can detect this, and reports it with an exception.

Resources