I want to integrate Telr Payment integration in my App, I have gone through the DOC part and it seems like I have to request for enabling mobile API. If anyone has a demo of Telr integration in iOS, please feel free to share it. I am unable to find any demo regarding this Telr payment integration.
I am giving you my demo but Every time I am getting error and it says type -"E" Code-01. If any one here has any idea please help me out. Actually I am making a testing demo and it may be possible that I am passing some wrong params but in actual I don't know which params are wrong.
NSString *paramString = [NSString stringWithFormat:
#"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<mobile:Body>\n"
"<store>%#</store>"
"<key>%#</key>"
"<device:Body>\n"
"<type>%#</type>"
"<id>%#</id>"
"<agent>%#</agent>"
"<accept>%#</<accept>"
"</device:Body>\n"
"<app:Body>\n"
"<name>%#</name>"
"<version>%#</version>"
"<user>%#</user>"
"<id>%#</<id>"
"</app:Body>\n"
"<tran:Body>\n"
"<test>%#</test>"
"<type>%#</type>"
"<class>%#</class>"
"<cartid>%#</<cartid>"
"<description>%#</description>"
"<currency>%#</currency>"
"<amount>%#</amount>"
"<ref>%#</<ref>"
"</tran:Body>\n"
"</mobile:Body>\n"
,#"123",#"XG32K#rBLn~BSm82",#"Simulator",#"xyzabc",#"",#"",#"Telr-Payment-Demo",#"1.0",#"Syscraft.Telr-Payment-Demo",#"",#"Test mode",#"PAYPAGE",#"",#"123",#"hello",#"AED",#"9.50",#""];
NSString *requestURL=#"https://secure.innovatepayments.com/gateway/mobile.xml";
NSURL *url=[NSURL URLWithString:requestURL];
NSData *data=[paramString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *mRequest = [[NSMutableURLRequest alloc] init];
[mRequest setURL:url];
[mRequest setHTTPMethod:#"POST"];
[mRequest setValue:[NSString stringWithFormat:#"%lu", (unsigned long)[data length]] forHTTPHeaderField:#"Content-Length"];
[mRequest setValue:#"application/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[mRequest setHTTPBody:data];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *responseData1 = [NSURLConnection sendSynchronousRequest:mRequest returningResponse:&response error:&error];
if (error!=nil)
{
NSLog(#"Webservice Error==%#",error);
}
else
{
NSString *responseDic =[NSJSONSerialization JSONObjectWithData:responseData1 options:NSUTF8StringEncoding error:&error];
if (error!=nil)
{
NSLog(#"Webservice Error==%#",error);
}
else
{
NSLog(#"responseDic ======\n %#",responseDic);
}
}
Related
If you are familiar with Parse.com's Javascript SDK, this is what I am trying to do for my own server for my iOS app (Objective-c). I want to be able to send some a string to the function that is on my server, have the server run its function and then return a string to the app or some xml or JSON data.
Is this even possible?
I am new to doing something like this having an app make a call to a server. I have looked into opening a port on my server, but have been unable to find a way to receive data back to the iOS app. (I found this lib but its for OS X https://github.com/armadsen/ORSSerialPort). Also Im not sure if I have a function run with an open port on the server. So how can I set it up so I can make a call to my server and run a function?
Any help would be much appreciated.
You just need to POST data to your server.
Port could be anything you want.
Host your script with a domain url so that you can make network request publicly.
You can try this function:
-(NSData *)post:(NSString *)postString url:(NSString*)urlString{
//Response data object
NSData *returnData = [[NSData alloc]init];
//Build the Request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:#"POST"];
[request setValue:[NSString stringWithFormat:#"%lu", (unsigned long)[postString length]] forHTTPHeaderField:#"Content-length"];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
//Send the Request
returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
//Get the Result of Request
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
bool debug = YES;
if (debug && response) {
NSLog(#"Response >>>> %#",response);
}
return returnData;
}
And here is how you use it:
NSString *postString = [NSString stringWithFormat:#"param=%#",param];
NSString *urlString = #"https://www.yourapi.com/yourscript.py";
NSData *returnData = [self post:postString url:urlString];
PHP
<?php
$response=array();
if(isset($_POST['param'])){
$response['success'] = true;
$response['message'] = 'received param = '.$_POST['param'];
}else{
$response['success'] = false;
$response['message'] = 'did not receive param';
}
$json = json_encode($response);
echo $json;
I want to send MMS using Twilio.
I am request one twilio url which is work fine on SMS but not MMS and I want to know what should change so i am sending MMS using Twilio in iOS.
Here is my code.
NSLog(#"Sending request.");
// Common constants
NSString *kTwilioSID =#"Twilio SID";
NSString *kTwilioSecret =#"Twilio Secret";
NSString *kFromNumber = #"From Phone Number";
NSString *kToNumber = #"To Phone number";
NSString *kMessage=#"Hello This is Pintu vasani";
// Build request
NSString *urlString = [NSString stringWithFormat:#"https://%#:%##api.twilio.com/2010-04-01/Accounts/%#/SMS/Messages", kTwilioSID, kTwilioSecret, kTwilioSID];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:#"POST"];
// Set up the body MediaUrl
NSString *bodyString = [NSString stringWithFormat:#"From=%#&To=%#&Body=%#", kFromNumber, kToNumber, kMessage];
NSData *data = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
NSError *error;
NSURLResponse *response;
NSData *receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// Handle the received data
if (error) {
NSLog(#"Error: %#", error);
} else {
NSString *receivedString = [[NSString alloc]initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(#"Request sent. %#", receivedString);
}
Twilio developer evangelist here.
You seem to be using the old, deprecated Sms resource which doesn't support MMS. You really want to be using the Messages resource which does work.
On a separate note, I would not recommend making API calls directly to Twilio from your iOS application (or any other client application). To do this you would need to embed your Twilio credentials within the application which is dangerous. I would recommend sending the SMS/MMS from a server side application as in this example.
I am trying to add ability to my app to post a new article to a wordpress blog. I know that Wordpress has the XMLRPC, but I am having issues in implementing the wp.newPost as there is little documentation outside of Ruby PHP or JAVA.
Here is what I have in my app:
-(IBAction)postNews {
NSURL *xmlrpcURL = [NSURL URLWithString:#"https://myurl.wordpress.com/xmlrpc.php"];
NSString *username = #"email#yahoo.com";
NSString *password = #"password";
NSString *title = #"Test";
NSString *content = #"This is a test of posting to the news section from the app.";
NSString *myRequestString = [NSString stringWithFormat:#"username=%#&password=%#&content=%#", username, password, title];
// Create Data from request
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: xmlrpcURL];
// set Request Type
[request setHTTPMethod: #"POST"];
// Set content-type
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"content-type"];
// Set Request Body
[request setHTTPBody: myRequestData];
// Now send a request and get Response
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(#"%#",response);
}
I constantly get the response:
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>-32700</int></value>
</member>
<member>
<name>faultString</name>
<value><string>parse error. not well formed</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
What am I doing wrong with this?
Ok, for those trying to do this, documentation for Obj-C is fairly difficult to find, but here is what I did. I first imported the XMLRPC Starter Kit from here. Next, in my app I defined the server username and password as it suggests, and in my action I used both an NSDictionary and NSArray for the post to go through. Again, this is for a simple text post to a wordpress blog.
NSString *server = kWordpressBaseURL;
XMLRPCRequest *reqFRC = [[XMLRPCRequest alloc] initWithHost:[NSURL URLWithString:server]];
NSDictionary* filter = #{
#"post_type": #"post",
#"post_status": #"publish",
#"post_title": #"Test Title",
#"post_content": #"Test Content",
};
NSArray *postParams = #[ #0, kWordpressUserName, kWordpressPassword, filter, #[#"post_title"]]; [reqFRC setMethod:#"wp.newPost" withObjects:postParams];
//The result for this method is a string so we know to send it into a NSString when making the call.
NSString *result = [self executeXMLRPCRequest:reqFRC];
[reqFRC release]; //Release the request
//Basic error checking
if( ![result isKindOfClass:[NSString class]] ) //error occured.
NSLog(#"demo.sayHello Response: %#", result);
Obviously, you can have text fields that you pull from for your blog post content, but this worked great!
U can add new posts using xmlrpc as given code
XMLRPCRequest *req = [[XMLRPCRequest alloc] initWithURL:[NSURL URLWithString:#"your url name"]];
NSArray *yourparameter = #[#0,#"your user id",#"your password"];
[request setMethod:#"wp.newPost" withParameters:yourparameter];
XMLRPCResponse *saveRessponse = [XMLRPCConnection sendSynchronousXMLRPCRequest:req error:nil];
NSLog(#"The Response is%#",[saveRessponse object]);
You can add new post using xml-rpc as
XMLRPCRequest *reqFRC = [[XMLRPCRequest alloc] initWithURL:[NSURL URLWithString:#"your url name"]];
// Set your url here.
NSArray *params = #[#0,#"your user id",#"your password"];
// Add your url parameters here.
[request setMethod:#"wp.newPost" withParameters:params]; // To add new post.
XMLRPCResponse *nodeSaveRessponse = [XMLRPCConnection sendSynchronousXMLRPCRequest:request error:nil];
NSLog(#"server response :%#",[nodeSaveRessponse object]);
I currently have a screen with 2 tables. I'm getting the data synchronously and putting it on the screen. Code looks something like:
viewController.m
DBAccess_Error_T = [getList:a byCompanyID:1];
DBAccess_Error_T = [getList:b byCompanyID:2];
[self putListAOnScreen];
[self putListBOnScreen];
DBAccess.m
+ (DBAccess_Error_T)getList:(NSMutableArray*)a byCompanyID:(NSInteger)cID
{
// Pack this up in JSON form
[self queryDB:postData];
// Unpack and put it into variable a
}
+ (id)queryDB:(id)post
{
// Send request
// Get back data
}
I'm now trying to switch this over to async and I'm struggling. It's been hard even with website tutorials and documentations.
Since all of my database utilities are in separate files from the viewControllers, I'm not sure how I can use the didReceiveData and didReceiveResponse handlers. Also, since I have 2 arrays to fill for my 2 tables, how do I distinguish the difference in didReceiveData?
Instead, what I'm trying to do now is use sendAsynchronousRequest, but it seems I need to create an unpack function for every send function...let me know if I'm way off here...it looks something like:
viewController.m stays the same
DBAccess.m
+ (DBAccess_Error_T)getList:(NSMutableArray*)a byCompanyID:(NSInteger)cID
{
NSDictionary *post = /*blah blah*/
[self queryDB:post output:(a)];
}
+ (id)queryDB:(id)post output:(id)output
{
NSError *error;
NSData *jsonPayload = [NSJSONSerialization dataWithJSONObject:post options:NSJSONWritingPrettyPrinted error:&error];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody:jsonPayload];
[NSURLConnection sendAsynchronousRequest:request
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error)
{
if ([data length] >0 && error == nil)
{
[self unpackDataForList:output data:data]; // This function needs to be different depending on which function called queryDB...the data will be unpacked in a different way
}
}
}
+ (void)unpackDataForList:(id)output data:(NSData*)data
{
// Do my unpacking here and stick it into 'output'.
}
How can I call a different unpackData function? are function pointers the right way to do this? Is this approach way off? Any tips would be greatly appreciated!
Have you ever looked at ASIHTTPRequest? It makes your life a lot easier by allowing you to use blocks. Here's an example of how to make an asynchronous request:
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://allseeing-i.com"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
}
You can find more information here:
http://allseeing-i.com/ASIHTTPRequest/
everyone! My english is poor and sorry fot that.
I want implement a function in my test iOS application.
There is a .NET Webservice API just like
"https://xxx.xxx.xx.xxx/FMS/Pages/Service/FMService.svc/Login"
I want to connect the API with two parameters:user and pass
using the GET method,and the url will be like:
"https://xxx.xxx.xx.xxx/FMS/Pages/Service/FMService.svc/Login?user=xxx&pass=xxx"
if login, the Webservice will return a JSON value just like {"d":"success"}
if not, it will also return a JSON value like {"d":"failure"}
I am using the ASIHTTPRequest framework and JSON framework
I dont know how to implement the function. So please help me, thanks a lot.
Best wishes!
NSURL *url = [NSURL URLWithString:#"https://192.168.1.245/FMS/Pages/Service/FMService.svc/Login?user=jiangxd&pass=123456"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addRequestHeader:#"Accept" value:#"application/json"];
[request addRequestHeader:#"Content-Type" value:#"application/json"];
[request setRequestMethod:#"GET"];
[request setDelegate:self];
[request startAsynchronous];
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *unlockCode = [responseDict objectForKey:#"d"];
NSLog(#"%#",unlockCode);
The unlockCode is always null... and I dont understand why!
NSURL *url = [NSURL URLWithString:#"https://192.168.1.245/FMS/Pages/Service/FMService.svc/Login?user=jiangxd&pass=123456"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error)
{
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *unlockCode = [responseDict objectForKey:#"d"];
NSLog(#"%#",unlockCode);
}
else
{
NSLog(#"%#",[error description]);
}
And now I change startAsynchronous to startSynchronous but there is also an error:
Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)" UserInfo=0x6b81640 {NSUnderlyingError=0x6b811b0 "The operation couldn’t be completed. (OSStatus error -9807.)", NSLocalizedDescription=A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)}
NOTICE:The url is https, not http!(Is this the reason that I get an error?)
But if I access the url directly with browser, the Webservice will return the right value...
Thank you!
You should probably try it, and then post your code. You're asking someone to write this entire function for you, and I don't think that that is the purpose of this site.
Secondly, the developer behind the ASIHTTPRequest is no longer supporting it. Unless the community picks up, you might want to just learn how to do NSURLConnections from scratch.
Edit: There we go. So, you're doing this asynchronosly which means that when you start it, you're not immediately going to have the response. Have you setup your callbacks to process the response?
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}