IOS: How to authenticate the GKLocalPlayer on my 'third party server'.
来源:互联网 发布:公司销售数据统计报表 编辑:程序博客网 时间:2024/06/05 07:03
参考:http://stackoverflow.com/questions/17408729/how-to-authenticate-the-gklocalplayer-on-my-third-party-server
https://gist.github.com/andyzinsser/8044165
工作总结:
任务说明:使用GameCenter账户作为游戏的账户。需要在本地服务器上验证登入信息。
主要参考https://gist.github.com/andyzinsser/8044165网站代码。
1.登入后给自己游戏服务器发post请求确认数据信息
流程:登入GameCenter-通过generateIdentityVerificationSignatureWithCompletionHandler获取相关信息-
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) { if (error) { NSLog(@"ERROR: %@",error); } else { [[GKLocalPlayer localPlayer] generateIdentityVerificationSignatureWithCompletionHandler:^(NSURL *publicKeyUrl, NSData *signature, NSData *salt, uint64_t timestamp, NSError *error) { if (error) { NSLog(@"ERROR: %@",error); } else{ // package data to be sent to server for verification NSDictionary *params = @{@"public_key_url": [publicKeyUrl absoluteString], @"timestamp": [NSString stringWithFormat:@"%llu", timestamp], @"signature": [signature base64EncodedStringWithOptions:0], @"salt": [salt base64EncodedStringWithOptions:0], @"player_id": [GKLocalPlayer localPlayer].playerID, @"app_bundle_id": [[NSBundle mainBundle] bundleIdentifier]}; NSError *JSONError = nil; NSData *JSONPOSTData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:&JSONError]; NSString *loginURL = /*your game sever*/; NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:loginURL]]; [postRequest setHTTPBody:JSONPOSTData]; [postRequest setHTTPMethod:@"POST"]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [NSURLConnection sendAsynchronousRequest:postRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { if (error) { NSLog(@"HttpPostError%@",error); } else { NSInteger responseCode = [(NSHTTPURLResponse*)response statusCode]; NSString *responseString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"HttpResponseCode:%d",responseCode); NSLog(@"HttpResponseString:%@",responseString); } }]; } }]; } }];
2. NSDictionary 转 JSON
NSDictionary *params = @{@"public_key_url": [publicKeyUrl absoluteString], @"timestamp": [NSString stringWithFormat:@"%llu", timestamp], @"signature": [signature base64EncodedStringWithOptions:0], @"salt": [salt base64EncodedStringWithOptions:0], @"player_id": [GKLocalPlayer localPlayer].playerID, @"app_bundle_id": [[NSBundle mainBundle] bundleIdentifier]}; NSError *JSONError = nil; NSData *JSONPOSTData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:&JSONError];
2.JSON 转 NSString
NSString *JSONPOSTString = [[NSString alloc] initWithData:JSONPOSTData encoding:NSUTF8StringEncoding];
3.JSON 转 NSDictionary
NSError *error =nil;
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:data options:kNilOptions error:&error];
0 0
- IOS: How to authenticate the GKLocalPlayer on my 'third party server'.
- How can I force WebLogic to use third party jars that are included in my Ear?
- How to install the third party modules under the pyCharm in the Windows
- How to set a breakpoint on a property within a third-party managed component?
- How to check the entitlements on my Application's Signature
- How to set third-party cookies with iframe?
- How to unintall the Mysql service on your server?
- How to Change the MySQL Timeout on a Server
- How to add third party jar in compile time but not runtime
- Maven:the way to add third-party jar-package to Local Maven Repository for using conveniently
- How the Swedish Pirate Party Platform Backfires on
- How to authenticate against the Active Directory by using Forms authentication and Visual C# .NET
- IOS Dev Intro - Third Party Library Process
- 解决Azure Management API ForbiddenError: The server failed to authenticate the request
- BEA-150021 - The admin server failed to authenticate the identity of the user username starting the managed server.
- iOS 如何在苹果电脑上安装svn 服务器(how to install svn server on the computer of mac os x)
- iOS 如何在苹果电脑上安装svn 服务器(how to install svn server on the computer of mac os x)
- How to install Oh My Zsh on Ubuntu 14
- OpenStack 源码中Nova几个基本概念
- 如何计算Farey序列的第n阶的全部项? UVa 10408 Farey sequences
- 80种可视化编程语言及其界面效果图
- 【redis】关于集群创建遇到的问题
- 存储 磁盘 文件系统 基本概念和命令
- IOS: How to authenticate the GKLocalPlayer on my 'third party server'.
- java web开发:ajax技术(二)—— 小数据传递的桥梁JSON
- 常用的验证数字字母组合的正则表达式
- 中介者模式(C++实现)
- undefined reference to
- 视频播放器实现原理
- DDX_CHECK引发的学习
- pentaho 5.0.1 迁移到mysql 数据库
- SQL 经典题目1