开发者

How to send strings from a PHP-server to an Objective-C client?

开发者 https://www.devze.com 2023-02-23 18:49 出处:网络
I\'ve got a server on which I can run PHP scripts and an application which is written in Ob开发者_如何学Pythonjective-C and Cocoa.

I've got a server on which I can run PHP scripts and an application which is written in Ob开发者_如何学Pythonjective-C and Cocoa.

What's the easiest way to send multiple strings (in my case 4) from the server to the client?


Easiest methods for receiving data/strings from the web:

For pure data:

NSData *myData = [NSData dataWithContentsOfURL:myURL];

For an actual string:

NSError *error = nil;
NSString *myString = [NSString stringWithContentsOfURL:myURL encoding:NSUTF8StringEncoding error:&error];
if (error) {
    NSLog(@"Could not receive string: %@", error);
}

These two calls fire a synchronous request, blocking your thread.
For asynchronous non-blocking requests read Apple's URL Loading System Programming Guide for full instructions.

0

精彩评论

暂无评论...
验证码 换一张
取 消