我有一個應用程序,每5秒發送一次地理位置,並且如果每分鐘沒有找到最新找到的位置的新位置。所以基本上,應用程序無法停止將地理位置發送到PHP文件。iOS停止隨機發送httprequests [鈦]
儘管如此。完全隨機的。該應用程序只是停止發送到服務器沒有錯誤(因爲我有我的onerror警報),並剛剛開始重新發送時,當我打開應用程序,看看發生了什麼事情。
它似乎在Android上順利運行!
我有一些東西在我的info.plist保持它活着(而且它保持它活着,但只是停留在隨機我猜住):
<key>UIBackgroundModes</key>
<array>
<string>external-accessory</string>
<string>location</string>
</array>
而且我的HttpRequest是這樣的:
function sendCoordinates() {
//Reset the visual text(errors/succesmessage etc)
if (Titanium.Network.online) {
//Concat the GPSholder array into the toSend and than empty the GPSholder.
//To toSend accumulates GPSholder arrays in case it can't be sent for some reason but avoids getting duplicates in the GPSholder
//the toSend is emptied out after a succesful save.
toSend = toSend.concat(getGPSholder());
GPSholder = [];
if (toSend.length > 0) {
GPSSaved.text = '';
minuteInterval = 0;
var xhr=Titanium.Network.createHTTPClient({enableKeepAlive: false});
xhr.open("POST","http://xxx.nl/website/services/esrm_tracker/push_tt_positions.php");
xhr.onload = function(){
if(this.status == '200'){
if(this.readyState == 4){
var result = JSON.parse(this.responseText);
switch(result.result) {
case 1:
secondsLastSent = 0;
counterBlock.text = "De laatste locatie is " + secondsLastSent + " seconden geleden verstuurd";
counterBlock.show();
toSend = [];
break;
case -1:
GPSSaved.text = 'Authorisatie code niet geldig. Er worden geen locaties meer verstuurd.';
GPSstop();
break;
case -2:
GPSSaved.text = 'Locaties niet geldig';
break;
case -3:
GPSSaved.text = 'Authorisatie code niet gevonden. Er worden geen locaties meer verstuurd.';
GPSstop();
break;
case -10:
GPSstop();
break;
default:
GPSSaved.text = 'Onbekende fout. Er worden geen locaties meer verstuurd.';
GPSstop();
break;
}
}
}
}
xhr.onerror = function(e){
GPSSaved.text = e.status + ' <- error';
alert(e);
};
xhr.timeout = 10000;
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
var str = JSON.stringify(toSend);
var params = {
auth_key : auth_key,
locations : str
};
xhr.send(params);
}
} else {
GPSSaved.text = 'Geen internet. Het versturen van locaties wordt hervat als de verbinding is hervat.';
}
}
作爲弗里斯蘭語,我很樂意在涉及「Elfstedentocht」的問題中給予支持。如果遇到更多問題,請與我聯繫 – 2013-04-24 11:06:05
感謝您的提議。如果這個問題能夠解決,我可能會在我的袖子上還有其他的東西去跟那個哈哈。儘管如此,我已經刪除了現在的鏈接哈哈 – CaptainCarl 2013-04-24 11:50:50