Skip to content

Commit

Permalink
mod: update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kelv1nq1an committed Dec 29, 2020
1 parent fcf2886 commit cc85b63
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 38 deletions.
6 changes: 6 additions & 0 deletions TdsDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
3F427CC9259B28450072677B /* TapDBViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F427CC8259B28450072677B /* TapDBViewController.m */; };
7B0662442591D3240000DE66 /* TapSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B0662432591D3240000DE66 /* TapSDK.framework */; };
7B560EA525903D12006840E1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B560EA425903D12006840E1 /* AppDelegate.m */; };
7B560EA825903D12006840E1 /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B560EA725903D12006840E1 /* SceneDelegate.m */; };
Expand All @@ -27,6 +28,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3F427CC7259B28450072677B /* TapDBViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TapDBViewController.h; sourceTree = "<group>"; };
3F427CC8259B28450072677B /* TapDBViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TapDBViewController.m; sourceTree = "<group>"; };
7B0662432591D3240000DE66 /* TapSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = TapSDK.framework; sourceTree = "<group>"; };
7B560EA025903D12006840E1 /* TdsDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TdsDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
7B560EA325903D12006840E1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -99,6 +102,8 @@
7B560EA725903D12006840E1 /* SceneDelegate.m */,
7B560EA925903D12006840E1 /* ViewController.h */,
7B560EAA25903D12006840E1 /* ViewController.m */,
3F427CC7259B28450072677B /* TapDBViewController.h */,
3F427CC8259B28450072677B /* TapDBViewController.m */,
7B560EAC25903D12006840E1 /* Main.storyboard */,
7B560EAF25903D13006840E1 /* Assets.xcassets */,
7B560EB125903D13006840E1 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -194,6 +199,7 @@
buildActionMask = 2147483647;
files = (
7B560EAB25903D12006840E1 /* ViewController.m in Sources */,
3F427CC9259B28450072677B /* TapDBViewController.m in Sources */,
7B560EA525903D12006840E1 /* AppDelegate.m in Sources */,
7B560EB625903D13006840E1 /* main.m in Sources */,
7B560EA825903D12006840E1 /* SceneDelegate.m in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions TdsDemo/TapDBViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TapDBViewController.h
// TdsDemo
//
// Created by Bottle K on 2020/12/29.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface TapDBViewController : UIViewController

@end

NS_ASSUME_NONNULL_END
31 changes: 31 additions & 0 deletions TdsDemo/TapDBViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// TapDBViewController.m
// TdsDemo
//
// Created by Bottle K on 2020/12/29.
//

#import "TapDBViewController.h"

@interface TapDBViewController ()

@end

@implementation TapDBViewController

- (void)viewDidLoad {
[super viewDidLoad];

}

/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
93 changes: 55 additions & 38 deletions TdsDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,145 +6,162 @@
//

#import "ViewController.h"
#import "TapDBViewController.h"
#import <TapSDK/TapSDK.h>
#import <TapSDK/TapDB.h>
#import <TapSDK/TapLoginHelper.h>
#import <TapSDK/TDSMoment.h>

@interface ViewController ()<TapLoginResultDelegate, TDSMomentDelegate>

- (void) initTapSDK;
- (void)initTapSDK;

@end


@implementation ViewController


- (void)viewDidLoad {
[super viewDidLoad];

UIButton *loginButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];
loginButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[loginButton setTitle:@"登录" forState:UIControlStateNormal];
[loginButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
[loginButton addTarget:self action:@selector(taptapLogin:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:loginButton];



UIButton *logoutButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 100, 50)];
logoutButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[logoutButton setTitle:@"登出" forState:UIControlStateNormal];
[logoutButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
[logoutButton addTarget:self action:@selector(taptapLogout:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:logoutButton];



UIButton *momentButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 100, 50)];

UIButton *profileButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 300, 50)];
profileButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[profileButton setTitle:@"获取用户最新信息" forState:UIControlStateNormal];
[profileButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
[profileButton addTarget:self action:@selector(fetchProfile:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:profileButton];

UIButton *momentButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 400, 100, 50)];
momentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[momentButton setTitle:@"打开动态" forState:UIControlStateNormal];
[momentButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
[momentButton addTarget:self action:@selector(taptapMoment:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:momentButton];


UIButton *momentRedPoint = [[UIButton alloc] initWithFrame:CGRectMake(100, 400, 300, 50)];

UIButton *momentRedPoint = [[UIButton alloc] initWithFrame:CGRectMake(100, 500, 300, 50)];
momentRedPoint.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[momentRedPoint setTitle:@"获取动态未读数" forState:UIControlStateNormal];
[momentRedPoint setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
[momentRedPoint addTarget:self action:@selector(taptapMomentRedPoint:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:momentRedPoint];


UIButton *dbButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 600, 300, 50)];
dbButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[dbButton setTitle:@"进入TapDB测试" forState:UIControlStateNormal];
[dbButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
[dbButton addTarget:self action:@selector(toTapDB:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:dbButton];

[self initTapSDK];
}

- (void) initTapSDK {

- (void)initTapSDK {
TDSConfig *config = TDSConfig.new;
config.clientId = @"FwFdCIr6u71WQDQwQN";

[TDSInitializer initWithConfig:config];
// 注册登录相关信息
[TapLoginHelper registerLoginResultDelegate:self];

// 开启 TapDB
[TDSInitializer enableTapDBWithChannel:@"default" gameVersion:@"1.0.0"];
NSLog(@"current profile %@", [TTSDKProfile currentProfile].toJsonString);
if ([TTSDKProfile currentProfile ] != nil) {
NSLog(@"current has user %@", [TTSDKProfile currentProfile].openid);
[TapDB setUser:[TTSDKProfile currentProfile].openid loginType:TapDBLoginTypeTapTap];
[TapDB setUser:[NSString stringWithFormat:@"%@_userid", [TTSDKProfile currentProfile].openid] loginType:TapDBLoginTypeTapTap];
}

// 开启 动态
[TDSInitializer enableMoment];
[TDSMomentSdk setDelegate:self];
}



#pragma mark - 登录相关

/**
登录
*/
- (void) taptapLogin:(UIButton *) button {

- (void)taptapLogin:(UIButton *)button {
[TapLoginHelper startTapLogin:@[@"public_profile"]];
}


/**
登出
*/
- (void) taptapLogout:(UIButton *) button {
- (void)taptapLogout:(UIButton *)button {
[TapLoginHelper logout];
}

/**
获取用户信息
*/
- (void)fetchProfile:(UIButton *)button {
[TapLoginHelper fetchProfileForCurrentAccessToken:^(TTSDKProfile *_Nonnull profile, NSError *_Nonnull error) {
if (error) {
NSLog(@"获取用户信息失败 %@", error);
} else {
NSLog(@"获取用户信息成功 %@", profile.name);
}
}];
}

- (void)onLoginSuccess:(TTSDKAccessToken *)token {
NSLog(@"Login success %@", [token toJsonString]);

// set user
[TapDB setUser:[TTSDKProfile currentProfile].openid loginType:TapDBLoginTypeTapTap];
}

- (void)onLoginCancel {
NSLog(@"Login cancel");

}

- (void)onLoginError:(AccountGlobalError *)error{
if (error != nil ) {
if ([LOGIN_ERROR_ACCESS_DENIED isEqualToString:error.error] || [LOGIN_ERROR_FORBIDDEN isEqual:error.error]) {
- (void)onLoginError:(AccountGlobalError *)error {
if (error != nil) {
if ([LOGIN_ERROR_ACCESS_DENIED isEqualToString:error.error] || [LOGIN_ERROR_FORBIDDEN isEqualToString:error.error] || [LOGIN_ERROR_INVALID_GRANT isEqualToString:error.error]) {
NSLog(@"当前 TOKEN已经失效, 需要提示用户重新执行 TapTap 登录流程");
}
}
NSLog(@"Login error %@", [error toJsonString]);
}

#pragma mark -
#pragma mark - 动态相关
/**
打开动态
*/
- (void) taptapMoment:(UIButton *) button {
- (void)taptapMoment:(UIButton *)button {
TDSMomentConfig *momentConfig = [[TDSMomentConfig alloc] init];
momentConfig.orientation = TDSMomentOrientationDefault;
[TDSMomentSdk openTapMomentWithConfig:momentConfig];
}


- (void) taptapMomentRedPoint:(UIButton*) button {
- (void)taptapMomentRedPoint:(UIButton *)button {
NSLog(@"小红点请求");
[TDSMomentSdk fetchNewMessage];
}


- (void)didChangeResultCode:(NSInteger)code msg:(NSString *)msg {
NSLog(@"didChangeResultCode %@ ,%d", msg, code);
NSLog(@"didChangeResultCode %@ ,%ld", msg, (long)code);
}

#pragma mark -
#pragma mark - DB相关

- (void)toTapDB:(UIButton *)button {
TapDBViewController *dbController = [TapDBViewController new];
[self presentViewController:dbController animated:YES completion:nil];
}

@end

0 comments on commit cc85b63

Please sign in to comment.