GUGameUpSDK 0.7.0

GUGameUpSDK 0.7.0

测试已测试
语言语言 Obj-CObjective C
许可证 Apache 2
发布时间上次发布2015年6月

Mo FirouzAndrei MihuChris MolozianMo Firouz 维护。



 
依赖于
AFNetworking~> 2.5.0
Base64nl~> 1.2
 

  • Mo Firouz、Chris Molozian 和 Andrei Mihu

GameUp iOS SDK 使用方法

GameUp 服务的 iOS SDK。

关于

GameUp 是专为游戏开发者提供的可扩展、可靠且快速的游戏服务。

该服务提供了游戏服务器今天提供的功能。我们的目标是让游戏开发者能够尽可能发挥创造力,打造出色游戏。通过利用 GameUp 服务,您可以轻松添加社交登录、玩家资料、云游戏存储等功能。

要查看完整功能列表,请查看我们的 主要文档

设置

客户端 SDK 可在 CocoaPods 上使用

它与 iOS 6 和 Xcode 4.4+ 完全兼容。

入门

要使用 GameUp SDK,首先您需要获取一个 ApiKey。您可以通过我们的 仪表板 获取。

SDK 使用 AFNetworking 进行网络调用,因此它是异步的。这意味着您可以请求某些信息,稍后您将获得包含所需数据的回调。要接收回调,您需要一个符合 GUResponderProtocol 的类。

// MyGameUpResponder.h
#import <Foundation/Foundation.h>
#import <GUResponderProtocol.h>

@interface MyGameUpResponder : NSObject <GUResponderProtocol>
@end
// MyGameUpResponder.m
#import "MyGameUpResponder.h"

@implementation MyGameUpResponder
- (void)failedPing:(NSInteger)statusCode withError:(NSError*) error
{
    // this is invoked when the ping fails to validate
        // either the ApiKey is invalid
        // or the Gamer Token is invalid
        // or the GameUp service is unreachable
}
- (void)retrievedGameData:(GUGame*)game
{
    // this is called whenever some game data is received.
}
// other methods that the protocol requires ...
@end

要使用 SDK,您需要创建一个 GUGameUp 类的实例,并在您的游戏中使用它。创建实例

// MyGameHelper.h
#import <GUGameUp.h>

@interface MyGameHelper : NSObject
@property(readonly) GUGameUp* gameup;
// ... other properties etc
@end
// MyGameHelper.m
#import "MyGameUpResponder.h"

static NSString *const MYGAME_API_KEY = @"your-api-key";

- (id)init {
    self = [super init];
    if (self) {
        // ... other init procedures you'd like to do!

        MyGameUpResponder *responder = [[MyGameUpResponder alloc] init];
        _gameup = [[GUGameUp alloc] initWithApiKey:MYGAME_API_KEY withResponder:responder];
    }
}
// other methods ...

登录

现在您已经有一个 GUGameUp 类的实例,我们将使用它来将玩家登录到系统中。

签名可以通过由 GUGameUpSDK 创建和维护的 UIWebView 完成。然而,此 UIWebView 将返回给您,以便您按需显示。

// MyGameHelper.m

// let's imagine that this is the method invoked when the gamer taps on 'Sign in' in your game.
- (void)onLoginClick 
{
    // Get or create a unique device ID
    UIDevice *device = [UIDevice currentDevice];
    NSString  *currentDeviceId = [[device identifierForVendor]UUIDString];
    // if you'd like to log the gamer in seamlessly...
    [_gameup loginAnonymouslyWith:currentDeviceId];

    // or if you'd like the gamer to login through Twitter using a webView:
    UIViewController* webViewController = [_gameup loginThroughBrowserToTwitter];
}
// other methods ...

一旦玩家通过他们选择的登录方式登录,您将获得之前定义的 MyGameUpResponder 的回调。

// MyGameUpResponder.m

// ... other methods ...

- (void)successfullyLoggedinWithSession:(id)session 
{
    // Called with the new session when login completes successfully.
    // You may want to:
    //  * Store it - most other gamer-specific method requires this session!
    //  * Permanently Store it and retrieve it when your game restarts using [session getGamerToken];
    //  * Update your game's state.
    //  * Welcome the user!
}
- (void)failedToLoginWithError:(NSError*) error
{
    // Called when some sort of error has occured...
}
- (void)loginCancelled
{
    // Called when the gamer has tapped on the 'Cancel' button...
}

// ... other methods ...

GameUp 推送

GameUp 推送设置非常简单。按照使用 APN 一样设置游戏,然后在以下方法重写中添加以下行

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token
{
    GUSession* session = ...;
    [session subscribePushWithDeviceToken:token];
}

更多文档

有关GameUp服务功能的高级示例和信息,请参阅我们的主要文档

注意

iOS SDK仍在变动中,我们正在寻找开发者的反馈,以确保我们设计的正是您需要构建卓越游戏的内容。请与我们联系,告诉我们我们可以如何改进。

贡献

所有对文档和代码库的贡献都热烈欢迎,请随意在跟踪器上打开有关文档改进的问题。

最后,我们总是欢迎拉取请求!:)