我正在尝试在flutter / objective-c中使用Dropbox API。对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"];
。