gpt4 book ai didi

ios - 链接到 Dropbox 后未调用 handleOpenURL - iOS

转载 作者:可可西里 更新时间:2023-11-01 05:02:34 25 4
gpt4 key购买 nike

我已经开始探索 Dropbox API 的应用程序,我希望用户能够在其中备份数据库文件。我遇到的问题是,在用户将应用程序与其帐户链接后(类似于通过 Facebook 登录),该应用程序不会返回到前台。当我手动返回到应用程序时,它仍在备份屏幕上,但帐户尚未链接(据我所知)并且未调用 handleOpenUrl 应用程序委托(delegate)方法。

有什么想法吗?或者也许有人知道一个很好的教程。示例 Dropbox 应用程序运行良好,我尽力将其用作指南,但显然我搞砸了。

应用委托(delegate):

#import "AppDelegate_iPad.h"
#import <DropboxSDK/DropboxSDK.h>
@interface AppDelegate_iPad () <DBSessionDelegate>

@end

@implementation AppDelegate_iPad

@synthesize window,viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.viewController = [[mainMenuViewController alloc]init];
[window addSubview:viewController.view]; //< this is a main menu viewcontroller for my app
[self.window makeKeyAndVisible];
// Set these variables before launching the app
NSString* appKey = @"XXXX";
NSString* appSecret = @"XXX";
NSString *root = kDBRootAppFolder;
NSString* errorMsg = nil;

if ([appKey rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound) {
errorMsg = @"Make sure you set the app key correctly in DBRouletteAppDelegate.m";
} else if ([appSecret rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound) {
errorMsg = @"Make sure you set the app secret correctly in DBRouletteAppDelegate.m";
} else if ([root length] == 0) {
errorMsg = @"Set your root to use either App Folder of full Dropbox";
} else {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
NSData *plistData = [NSData dataWithContentsOfFile:plistPath];
NSDictionary *loadedPlist =
[NSPropertyListSerialization
propertyListFromData:plistData mutabilityOption:0 format:NULL errorDescription:NULL];
NSString *scheme = [[[[loadedPlist objectForKey:@"CFBundleURLTypes"] objectAtIndex:0] objectForKey:@"CFBundleURLSchemes"] objectAtIndex:0];
if ([scheme isEqual:@"db-APP_KEY"]) {
errorMsg = @"Set your URL scheme correctly in DBRoulette-Info.plist";
}
}

DBSession* session =
[[DBSession alloc] initWithAppKey:appKey appSecret:appSecret root:root];
session.delegate = self; // DBSessionDelegate methods allow you to handle re-authenticating
[DBSession setSharedSession:session];
[session release];

if (errorMsg != nil) {
[[[[UIAlertView alloc]
initWithTitle:@"Error Configuring Session" message:errorMsg
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]
autorelease]
show];
}


NSURL *launchURL = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSInteger majorVersion =
[[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] integerValue];
if (launchURL && majorVersion < 4) {
// Pre-iOS 4.0 won't call application:handleOpenURL; this code is only needed if you support
// iOS versions 3.2 or below
[self application:application handleOpenURL:launchURL];
return NO;
}


return YES;
}


- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { /// this is never called
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"App linked successfully!");
// At this point you can start making API calls
}
return YES;
}

return NO;
}







@end

在主菜单中,用户按下了一个备份按钮并打开了以下 View Controller :

#import "BackupManagerViewController.h"
#import <DropboxSDK/DropboxSDK.h>
#import <stdlib.h>


@interface BackupManagerViewController () <DBRestClientDelegate>



//@property (nonatomic, readonly) DBRestClient* restClient;

@end

@implementation BackupManagerViewController
@synthesize itemsArray,delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}



#pragma mark - View lifecycle

- (void)viewDidLoad
{

//[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
return (orientation != UIDeviceOrientationLandscapeLeft) &&
(orientation != UIDeviceOrientationLandscapeRight);
}


- (IBAction)didPressLink {
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] link];
} else {
[[DBSession sharedSession] unlinkAll];
[[[[UIAlertView alloc]
initWithTitle:@"Account Unlinked!" message:@"Your dropbox account has been unlinked"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]
autorelease]
show];

}
}


-(DBRestClient *)restClient{
if (restClient == nil) {
restClient = [[DBRestClient alloc]initWithSession:[DBSession sharedSession]];
restClient.delegate = self;
}

return restClient;
}

-(IBAction) closeButtonPressed {
[delegate closeBackupManager];
}


@end

最佳答案

要检查的是

  1. 确保您没有两个应用程序具有相同的 db-APP_KEY
  2. 确保在您的应用程序委托(delegate)中只实现其中一个(而不是两个)。

    (一)- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

    (二)- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

    选项 (b) 已弃用,因此请在您的新应用程序中使用选项 (a)

  3. 您在 URL 方案中输入了正确的 APP_KEY

关于ios - 链接到 Dropbox 后未调用 handleOpenURL - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8482369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com