RQDouYinManager.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // RQDouYinManager.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/5/12.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQDouYinManager.h"
  9. #import <DouyinOpenSDK/DouyinOpenSDKAuth.h>
  10. @interface RQDouYinManager() <DouyinOpenSDKLogDelegate>
  11. @property (nonatomic, readwrite, strong) NSString *clientKey;
  12. @property (nonatomic, readwrite, strong) NSString *clientSecret;
  13. @end
  14. @implementation RQDouYinManager
  15. @def_singleton(RQDouYinManager);
  16. #pragma mark - PublicMethods
  17. - (NSString *)clientKey {
  18. return @"awbewr7xlianfnew";
  19. }
  20. - (NSString *)clientSecret {
  21. return @"dd979dc2a5ddcc0c761fcbe899d87ba1";
  22. }
  23. /// 初始化
  24. - (void)initDouYinManagerWithApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  25. dispatch_async_on_main_queue(^{
  26. [[DouyinOpenSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
  27. [DouyinOpenSDKApplicationDelegate sharedInstance].logDelegate = self;
  28. });
  29. }
  30. /// 调起登录
  31. - (void)douyinLogin {
  32. DouyinOpenSDKAuthRequest *request = [[DouyinOpenSDKAuthRequest alloc] init];
  33. request.permissions = [NSOrderedSet orderedSetWithObject:@"user_info"];
  34. //可选附加权限(如有),用户可选择勾选/不勾选
  35. // request.additionalPermissions = [NSOrderedSet orderedSetWithObjects:@{@"permission":@"friend_relation",@"defaultChecked":@"1"}, @{@"permission":@"message",@"defaultChecked":@"0"}, nil];
  36. [request sendAuthRequestViewController:RQControllerHelper.currentViewController completeBlock:^(DouyinOpenSDKAuthResponse * _Nonnull resp) {
  37. NSString *alertString = nil;
  38. if (resp.errCode == 0) {
  39. // alertString = [NSString stringWithFormat:@"Author Success Code : %@, permission : %@",resp.code, resp.grantedPermissions];
  40. [MBProgressHUD rq_showTips:@"授权成功"];
  41. [RQNotificationCenter postNotificationName:RQDouYinOnRespNotification object:resp.code];
  42. } else{
  43. #if DEBUG
  44. alertString = [NSString stringWithFormat:@"Author failed code : %@, msg : %@",@(resp.errCode), resp.errString];
  45. alertString = [NSString stringWithFormat:@"%@",resp.errString];
  46. #else
  47. alertString = [NSString stringWithFormat:@"%@",resp.errString];
  48. #endif
  49. [NSObject rq_showAlertViewWithTitle:alertString message:nil confirmTitle:@"确定"];
  50. }
  51. }];
  52. }
  53. #pragma mark - PrivateMethods
  54. #pragma mark - DouyinOpenSDKLogDelegate
  55. - (void)onLog:(nonnull NSString *)logInfo {
  56. }
  57. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  58. if ([[DouyinOpenSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]) {
  59. return YES;
  60. }
  61. return NO;
  62. }
  63. @end