Hey guys I'm kinda new into swift programming, currently I'm making an iOS apps and facing a problem
I have one textfield and one textview in my view controller, I'm supposed to connect the application into a web service, so when I input number in the textfield, the apps will print the return value in the textview. But i don't know what to code in the Xcode to communicate the apps with the server.
This is the code of the web service
<?php error_reporting(E_ERROR | E_PARSE);
include 'koneksi.php';
$nama = $_REQUEST['nama'];
$query = ("select * from pegawai where nip='$nama' or no_kpe='$nama'");
$exe = mysql_query($query);
if($row = mysql_fetch_assoc($exe)){
$c = TRIM($row['nama']);
$a = NUMBER_FORMAT($row['tht']);
$b = NUMBER_FORMAT($row['pensiun']);
if($a == 0){
echo "Nama = ".$c."\n";
echo "THT = Sedang Dilakukan Peremajaan Data Keluarga"."\n";
echo "Pensiun = Rp. ".$b;
}
else{
echo "Nama = ".$c."\n";
echo "THT = Rp. ".$a."\n";
echo "Pensiun = Rp. ".$b;
}
}
else {
echo "Mohon Periksa Kembali Notas atau No. KPE anda."."\n";
}
?>
I'm using Xcode 7 and running the apps in iOS 9.0
I'm new in this language and also web service so step by step answer will be much appreciated
You need to use the NSURLSession API to connect to a remote web service. I suggest using AFNetworking. It is an easy to use framework that makes network request and serialization for you.
Related
i've just copied the example of a whatsapp bot in the post to test whatsapp API: https://www.twilio.com/blog/php-twilio-whatsapp
script for Send message is working properly (i'm using sandbox). But the callback is not working. i get the 11200 - HTTP retrieval failure. Someone could analyse my code below? note that i downloaded the SDK not via composer.
<?php
require __DIR__ . '/twilio-php-main/src/Twilio/autoload.php';
use Twilio\Twiml;
$response = new Twiml;
$guess = $_REQUEST['Body'];
$pick = rand(1,5);
if (!in_array($guess, [1,2,3,4,5])) {
$response->message("Hiya! I'm thinking of a number between 1 and 5 - try to guess it!");
} elseif ($guess == $pick) {
$response->message("Yes! You guessed it!");
} else {
$response->message("Nope, it was actually $pick - Pick a new number to play again!");
}
print $response;
folks!
I'm trying to run an HTML app in Trigger.io. This app calls ajax to load some data from a PHP page. At this moment, I authenticate the user and start the session. After this, I have to call another PHP page. So, I check for the session started, and I found that the session is not active anymore. The second call is made right after the first one.
This happens when I try to run the app from the Trigger.io ToolKit, using iOS Simulator ( I'm using a Mac - OS X Mountain Lion ). When I test the same app in the Safari, it works perfectly: my PHP server recognizes the session started earlier, and the second page is loaded by ajax.
Is there any parameter I have to set? Or Trigger.io does not support PHP sessions?
Thank you.
Marcio
You should use forge.request.ajax(params) to make ajax requests, this is because of cross domain restrictions, as Forge apps are loaded as file:// urls on iOS.
forge.ajax.request takes a similar input to jQuery's $.ajax so you can easily switch between them if you want to use the same code on a website as well as in your Forge app.
More documentation is available in our docs: http://docs.trigger.io/en/v1.4/modules/request.html#ajax
#Connorhd , thank you so much for helping!
First of all, I do an ajax request to "app_authUser.php" to authenticate user. Then, if Ok, I do another ajax request to "app_loadFeed.php" to load data from server.
In the first ajax request, I pass, in the post parameters, the user data ( login and password ) to authenticate the user on database. The first command I call on the php file "app_authUser.php" is "session_start()", as follow:
CODE FOR "app_authUser.php" ON THE SERVER SIDE:
<?php
session_start();
// Just for test;
$idSession = session_id();
echo $idSession;
/*
Test user authenticate. If ok, then I assign idUser to $_SESSION['idUser'] variable.
*/
if( $loginOk == true ){
$_SESSION[ 'idUser' ] = $User->idUser;
}
?>
In the code above, the user is authenticated and $_SESSION['idUser'] is correctly initiated. In the second ajax request, I test if the variable $_SESSION[ 'idUser' ] is set. That's the point: it isn't set anymore. Again, I call "session_start()" at first:
CODE FOR "app_loadFeed.php" ON THE SERVER SIDE:
<?php
session_start();
// Just for test;
$idSession = session_id();
echo $idSession;
if( isset( $_SESSION[ 'idUser' ] ) ){
/* Load data from database to return to user.... */
echo ...
}
else{
echo '0';
}
?>
The test above always return false when I call my app from Trigger.io compiler. But, when I call my app from Safari, it always returns true.
I found out that the function "session_id()" returns different values in both ajax requests when the call is made from app running on Trigger.io compiler, but the same value when app is running on Sarari:
Example:
Requests from Trigger.io:
First request: echo $idSession returns "m7dbsv7qqem92os39lv5ao2ta1"
Second request: echo $idSession returns "h49pble06n7ao9pum06kt4dph0"
Requests from Safari:
First request: echo $idSession returns "2cbhin1185fm5ehvbb15k6n0b1"
Second request: echo $idSession returns "2cbhin1185fm5ehvbb15k6n0b1"
That means the session isn't the same at the first example. Why does this happen?
I'm not using forge.request.ajax in my app. That's my ajax code, in my javascript:
<script>
function openAjax()
{
try
{
var ajax = new XMLHttpRequest();
}
catch(e)
{
try
{
var ajax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(ee)
{
try
{
var ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(eee)
{
var ajax = false;
alert("Seu navegador não suporta AJAX!")
}
}
}
return ajax;
}
// This is the function called at second time, just after I authenticate my user and have session opened.
function loadFeed(){
var url = CT_URLBase + 'app_loadFeed.php'; // CT_URLBase = 'http://192.168.1.100/' in my local environment.
var parameters = '';
var ajax = openAjax();
ajax.open('POST', url, true);
ajax.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=iso-8859-1');
ajax.onreadystatechange = function(){
if (ajax.readyState == 4){
if (ajax.status == 200){
var retorno = ajax.responseText;
if( retorno != '0' ){
/* Return OK!!! */
}
else{
/* Error: return is 0 (zero), that means session is not started.
}
}
}
}
ajax.send(parameters);
}
</script>
What most makes me in a misunderstanding is that the same code works perfectly in Safari, but not in Trigger.io.
By the way, I visited your website, connorhd.co.uk ! Great job! It's a great place to find "Interesting stuff"! Congratulations!
Thank you so much for your help!!!
Marcio Clume
I'm using prestashop and i want to run a/b test. It means you test 2 different templates of your website in the same time as the traffic is redirected 50% to templateA and 50% to templateB.
I have to theme in my folder :
-ThemeA
-ThemeB
To run the test i need to access themeB via a different url form themeA.
So in the folder "/config" i modified the file setting.inc.php like this :
if(isset($_GET['ab']))
{
define('_THEME_NAME_', 'themeB');
}
else{
define('_THEME_NAME_', 'themeA');
}
Now i can reach themeb by typing : www.myshop.com/?ab
My problem is, whenever i click a link, the ?ab parameter is lost and it goes back to template A.
I found someone using another cms that resolved to problem using this code :
`$this->redirect(array('name')); `
But i don't know how to adapt it to prestashop and where should i put it.
Any help would be very appreciated.
Thanks
One quick workaround might be using session, if session is started ([http://sg3.php.net/manual/en/function.session-start.php][1]) before your "theme check".
// Page => watermelons.php
<?php
session_start();
if(isset($_GET['ab']) || isset($_SESSION['ab'])) {
$_SESSION['ab'] = 'themeB';
define('_THEME_NAME_', 'themeB');
} else{
define('_THEME_NAME_', 'themeA');
}
echo _THEME_NAME_;
?>
<br />go to coconuts
// Page => coconuts.php
<?php
session_start();
if(isset($_GET['ab']) || isset($_SESSION['ab'])) {
$_SESSION['ab'] = 'themeB';
define('_THEME_NAME_', 'themeB');
} else{
define('_THEME_NAME_', 'themeA');
}
echo _THEME_NAME_;
?>
<br />go to watermelons
I am working on a USSD client. Everything works fine except for closing a distant USSD session.
In the specification, we can see the function CUSD:
AT+CUSD=2 should close the USSD session, but this is not really the case.
In fact when I do this sequence:
AT+CUSD='#xxx#',12
AT+CUSD='1',12
I have an open distant connection.
On your handset, you can open a new session by dialing #xxx*#
If I send a:
AT+CUSD='#xxx*#',12
This is not opening a new distant session.
If I send a:
AT+CUSD=2
AT+CUSD='#xxx#'
This is not opening a new distant session.
Do you know how to close a distant session?
I am working with huwaei key E160 and E173 on windows or Linux.
Use in the following way.
AT+CUSD='#xxx#',15
AT+CUSD=2
I am posting this because this is the top result regarding terminating USSD sessions using AT commands and also because the answers are vague.
This is the c# code i used in the end(I was sending the commands to a gsm modem). Hope it helps someone else
SerialPort SendingPort=null;
public string TerminateUssdSession()
{
InitializePort();
//// generate terminate command for modem
string cmd = "";
cmd = "AT+CUSD=2\r";
// send cmd to modem
OpenPort();
SendingPort.Write(cmd);
Thread.Sleep(500);
string response = SendingPort.ReadExisting();
return response;
}
private void InitializePort()
{
if (SendingPort == null)
{
SendingPort = new SerialPort();
SendingPort.PortName = PortName;//put portname here e.g COM5
SendingPort.BaudRate = "112500";
SendingPort.Parity = Parity.None;
SendingPort.DataBits = 8;
SendingPort.StopBits = StopBits.One;
SendingPort.Handshake = Handshake.None;
SendingPort.ReadTimeout = 500;
}
}
private void OpenPort()
{
if (!SendingPort.IsOpen)
{
SendingPort.Open();
}
}
I have this SOAP request that I use in php to get some information, but I can't seem to figure out how to do this in Xcode, hopefully somebody can point me in the right direction
<?php
$wsdl_url = "https://www.service.com/mySoapService.wsdl";
$client = new SoapClient($wsdl_url);
var_dump($client->__getFunctions());
try {
$userName = 'myUsername';
$password = 'myPassword';
$result = $client->retrieveUsage(new SoapParam(array("UserId" => $userName, "Password" => $password), "RetrieveUsageRequestType"));
print '<pre>';
print_r($result);
print '</pre>';
} catch (Exception $e) {
echo $e->getMessage();
}
?>
Add your WSDL, create stubs and off you go, start using your web-service from iOS apps.
http://sudzc.com/
I hope this is what you are looking for.
Enjoy!
I used http://easywsdl.com to generate classes. Works perfect with my WS