Я пытаюсь использовать API dropbox с flutter / target-c. Абсолютно новый для Objective-C программирования, так что если мне трудно понять, полностью.
Каждый раз, когда я иду, чтобы разрешить доступ для пользователя, он выдает ошибку 403 или отказ в доступе.
#import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[DBClientsManager setupWithAppKey:@"APPKEY"];
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
FlutterMethodChannel* dropBoxLogin = [FlutterMethodChannel methodChannelWithName: @"xante.flutter.dev/dropbox" binaryMessenger: controller];
[dropBoxLogin setMethodCallHandler: ^(FlutterMethodCall* call, FlutterResult result){
if ([@"retrieveAccessToken" isEqualToString:call.method]) {
[self myButtonInControllerPressed];
}
else{
result(FlutterMethodNotImplemented);
}
}];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (void)myButtonInControllerPressed {
[DBClientsManager authorizeFromController:[UIApplication sharedApplication]
controller:[[self class] topMostController]
openURL:^(NSURL *url) {
[[UIApplication sharedApplication] openURL:url];
}];
}
+ (UIViewController*)topMostController
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
if (authResult != nil) {
if ([authResult isSuccess]) {
NSLog(@"Success! User is logged into Dropbox.");
} else if ([authResult isCancel]) {
NSLog(@"Authorization flow was manually canceled by user!");
} else if ([authResult isError]) {
NSLog(@"Error: %@", authResult);
}
}
return NO;
}
Мне любопытно, если у меня есть [DBClientsManager setupWithAppKey:@"APPKEY"];
в неправильном месте.