Appearance
初始化
WARNING
初始化接口,需要在游戏启动时,尽快调用, 否则影响后续接口的调用。
引入库文件
所有接口调用,都通过UGSDKPlatform 单例类来调用。 在调用接口之前,需要先引入头文件:
objc
#import <UGSDK/UGSDKPlatform.h>
设置SDK回调代理
当初始化、登录、登出、支付等接口调用之后, 响应的调用结果,SDK会触发UGSDKDelegate
中的对应的回调函数, 您可以实现UGSDKDelegate
来监听对应的回调函数,并针对性地处理业务逻辑。
点击查看代码
objc
// 初始化成功后回调
-(void) onUGInitSuccess{
NSLog(@"sdk init success");
}
// 初始化失败后回调
-(void) onUGInitFailed:(NSString*)msg{
NSLog(@"sdk init failed.%@", msg);
}
// 登录成功后回调
-(void) onUGLoginSuccess:(UG_UserDataModel*)result{
NSLog(@"sdk login success: %@", result);
}
// 登录失败后回调
-(void) onUGLoginFailed:(NSString*)msg{
NSLog(@"sdk login failed: %@", msg);
}
// 登出成功后回调
- (void)onUGLogoutSuccess:(BOOL)fromUserCenter {
NSLog(@"logout from sdk");
if (fromUserCenter) {
// 说明玩家从SDK的悬浮窗中点击了登出账号,游戏这里需要让玩家返回到游戏登录界面,并打开SDK的登录界面,让玩家重新登录
}
}
// 登出失败后回调
-(void) onUGLogoutFailed:(NSString*)msg{
NSLog(@"sdk logout failed");
}
// 支付成功后回调
-(void) onUGPaySuccess:(NSString*)msg{
NSLog(@"sdk pay success");
}
// 支付失败后回调
-(void) onUGPayFailed:(NSString*)msg{
NSLog(@"sdk pay failed: %@", msg);
}
调用初始化接口
调用初始化接口,一般在游戏启动的时候调用。 后续其他接口的调用都必须在初始化接口调用之后进行。
// SDK 初始化
NSString *appID = @"1"; //appid
NSString *appKey = @"111"; //appkey
NSString *orientation = @"landscape"; //横竖屏;横屏:landscape; 竖屏:portrait
UG_SDKParams* sdkParams = [[UG_SDKParams alloc] initWithAppID:appID appKey:appKey orientation: orientation];
[[UGSDKPlatform sharedInstance]initWithParams:sdkParams delegate:self]; //第二个delegate参数,就是实现了上面UGSDKDelegate的类
初始化参数说明:
参数名称 | 参数类型 | 参数说明 |
---|---|---|
appID | String | 当前游戏的appID参数,如果还没有该参数,请参考:获取参数 |
appKey | String | 当前游戏的appKey参数,如果还没有该参数,请参考:获取参数 |
orientation | String | 游戏横竖屏,portrait:竖屏; landscape:横屏 |
实现生命周期函数
需要在AppDelegate以下对应的生命周期方法中调用U8SDK种对应这些方法:
点击查看代码
objc
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [[UGSDKPlatform sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
return [[UGSDKPlatform sharedInstance] application:application openURL:url options:options];
}
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [[UGSDKPlatform sharedInstance] application:application handleOpenURL:url];
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [[UGSDKPlatform sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[[UGSDKPlatform sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
{
[[UGSDKPlatform sharedInstance] application:application didReceiveRemoteNotification:userInfo];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[[UGSDKPlatform sharedInstance] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[[UGSDKPlatform sharedInstance] application:application didReceiveLocalNotification:notification];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
[[UGSDKPlatform sharedInstance] applicationWillResignActive:application];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[UGSDKPlatform sharedInstance] applicationDidEnterBackground:application];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[UGSDKPlatform sharedInstance] applicationWillEnterForeground:application];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UGSDKPlatform sharedInstance] applicationDidBecomeActive:application];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[[UGSDKPlatform sharedInstance] applicationWillTerminate:application];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
[[UGSDKPlatform sharedInstance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
return YES;
}