Burak Ogutken
Burak Ogutken

Reputation: 690

how to call url with parameters in Xcode

i have one php file for push notification service and working.. i want use that php file in xcode, for example send device token and message like an query string..

i used this code

NSString *urlString = @"http://xxxxxx.com/send-notification.php?token=%@&message=test";                       
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",escapedString,token]];`

but not working i don't know how to call this php..

thanks for all helps

Upvotes: 2

Views: 3654

Answers (1)

Emiel vl
Emiel vl

Reputation: 186

You will need to create your url in a different way. In your code, the %@ in the initial urlString will not be replaced later on.

Instead, try writing your code like this:

NSString *urlString = [NSString stringWithFormat:@"http://xxxxxx.com/send-notification.php?token=%@&message=test", token];
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:escapedString];

After you've created the NSUrl instance, you will have to open a http connection to the url.

Upvotes: 1

Related Questions