开发者

Database connection through PHP & HTTPS for iPhone

Would it be sufficient to get data through a HTTPS connection into an iPhone app via PHP (the PHP files are l开发者_运维问答ocated on the same web server as a MySQL database)?

I'm speaking in terms of security.

Also, would this be a tideous process (with too many overheads) or can it work in terms of performance?

Thanks in advance.


I have added HTTP authentication to the security scheme you describe--so my directory containing the PHP scripts that receive web requests from my iPhone app and emit JSON in return is behind basic web-server-level authentication. Not a LOT stronger, but it at least prevents nosy URL-twiddlers from finding their way in there.

I recommend the following third-party libraries for this:
ASIHTTPRequest
JSON Framework

Using those two things, a -viewDidLoad method might contain this:

NSString *urlStr = @"http://username:password@myrequest.com/myjsonscript.php";
ASIHTTPRequest *r = [ASIHTTPRequest requestWithUrl:
                     [NSURL urlWithString:urlStr]];
[r setCompletionBlock:^{
    NSDictionary *results = [[r responseString] JSONValue];
    //do whatever to display the background-downloaded data 
    //(possibly [self.tableView reloadData] or something like that)
}];
[r startAsynchronous];

Just that simple.


this is one of the best solutions i've used for accessing mysql from an iphone app (indirectly through PHP) http://tempered.mobi/

Sorry for some reason, i cant hyperlink straight to the article. But if you press Articles and then mysql json PHP, you'll see the relevant tutorial

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜