创建高分系统,iPhone端 [英] Creating a highscore like system, iPhone side

查看:53
本文介绍了创建高分系统,iPhone端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于打开一个新问题我感到很抱歉,我不得不-当我以未注册用户的身份从我的iPhone编写另一个问题时,用iPhone编写不是很舒服.

I'm sorry for opening a new question, I had to - as I wrote the other question from my iPhone as unregistered user and it is not very comfortable to write from the iPhone.

重述问题:

是否可以使用:

[NSMutableArray writeToURL:(NSString *)原子路径:(BOOL)AuxSomething];

[NSMutableArray writeToURL:(NSString *)path atomically:(BOOL)AuxSomething];

为了将文件(NSMutableArray)XML文件发送到URL,并更新该URL以包含该文件?

In order to send a file (NSMutableArray) XML file to a url, and update the url to contain that file?

例如:我有一个数组,我想将其上传到特定的URL,下次应用启动时,我要下载该数组.

for example: I have an array and I want to upload it to a specific URL and the next time the app launches I want to download that array.

NSMutableArray * arrayToWrite = [[NSMutableArray alloc] initWithObjects:@一个",@两个",nil];

NSMutableArray *arrayToWrite = [[NSMutableArray alloc] initWithObjects:@"One",@"Two",nil];

[arrayToWrite writeToURL:

[arrayToWrite writeToURL:

[NSURL urlWithString:@" mywebsite.atwebpages.com/myArray.plist"]原子地:是];

[NSURL urlWithString:@"mywebsite.atwebpages.com/myArray.plist"] atomically:YES];

在运行时:

NSMutableArray * arrayToRead =

NSMutableArray *arrayToRead =

[[[NSMutableArray alloc] initWithContentsOfURL:[NSURL urlWithString:@" mywebsite.atwebpages.com/myArray.plist"]]];

[[NSMutableArray alloc] initWithContentsOfURL:[NSURL urlWithString:@"mywebsite.atwebpages.com/myArray.plist"]];

意思是,我想将NSMutableArray写入Web托管服务
(例如batcave.net)上的URL,该URL接收信息并相应地更新服务器端文件.像设置这样的高分,用户发送分数,服务器更新其文件,其他用户在运行时下载高分.

Meaning, I want to write an NSMutableArray to a URL, which is on a web hosting service
(e.g. batcave.net), the URL receives the information and updates server sided files accordingly. A highscore like setup, user sends his scores, the server updates it's files, other users download the highscores at runtime.

我希望这一点得到澄清.

I hope this is clarified.

我正在寻找的是编写PHP或ASP脚本,因此将数据发送到的网站,URL知道如何处理.如果可能的话,我想要一个示例或教程来介绍如何实现此脚本来处理数据.

What I am looking for is scripting PHP or ASP so the website, the URL where the data is sent to would know how to handle it. I want an example or a tutorial on how to implement this scripting for handling data, if it's possible to do this on a web hosting service.

〜先谢谢.

推荐答案

要回答如何创建像系统一样的高分?"这个问题,系统有多个部分:

To answer the question "How do I create a high score like system?", there are multiple parts of the system:

  • 您需要为每个用户提供一个ID(在iPhone上生成的GUID以及用户名就足够了.)
  • 您需要一个服务器:记住高分;受到用户的好评;要么(在网站上)显示高分和/或使高分可下载到手机.
  • 您需要一些欺诈保护,尽管这可能会在与越狱者的失败斗争中胜出.

在iPhone应用程序方面,您可能希望能够下载当前的高分显示,这很容易完成,例如:

On the iPhone app side, you might want to be able to download the current high scores for display, which is done easily enough with something like:

int statusCode = 0;
NSData* result = nil;
NSHTTPURLResponse* response = nil;
NSError* error = nil;
NSString* url = @"http://www.yourserver.com/highscores.php"; // returns XML plist data
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:180];
result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//  NSLog( @"NSURLConnection result %d %@ %@", [response statusCode], [request description], [error description] );
statusCode = [response statusCode];
if ( (statusCode == 0) || (!result && statusCode == 200) ) {
    statusCode = 500;
}

由于它是同步的,因此您可能希望将其放入NSOperation中.或者,您可以使用

Since it is synchronous, you might want to put it inside an NSOperation. Alternatively, you can use

+ (NSURLConnection *)connectionWithRequest:(NSURLRequest *)request delegate:(id)delegate

要发送高分数据,因为它是如此之小,最简单的方法就是将其编码为URL.

To send high score data, because it is so small, the easiest way is simply to encode it in the URL.

NSString* url = [NSString stringWithFormat:@"http://www.yourserver.com/sethighscores.php?uid=%@;name=%@;score=%d;antifraud=%@", [uid encodeParameter], [name encodeParameter], score, [secureHash encodeParameter]];

其中encodeParameter是NSString上的自定义类别,该类别编码URL参数,而secureHash是一个字符串,该字符串表示对iPhone应用程序和网站已知的uid,名称,分数和某些机密的一种安全哈希.由于这已经很长了,您需要自己解决这些问题或提出其他问题.

Where encodeParameter is a custom category on NSString that encodes URL parameters and secureHash is a string representing a one way secure hashing of the uid, name, score and some secret known to your iPhone app and your web site. You'll need to figure these out on your own or ask separate questions since this is already getting long.

这篇关于创建高分系统,iPhone端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆