使用 DropBox SDK 的 iPhone 应用程序未调用 handOpenURL
我使用的是 MacOSX 10.6,Xcode 模拟器是 4.2,但是在尽力之后,handleOpenURL 没有在我实现它的 appdelegate.m 文件中被调用。我已按照 DropBox 网站中给出的教程中的所有说明进行操作(DropBox 教程 ),
但是,一旦用户允许我的应用程序访问,通过 safari 从 dropbox 帐户登录后,控件将重定向到我的“Link with DropBox”视图,即用户有机会登录的视图,
问题也就是说,没有调用handleOpenURL方法,也没有调用didfinishWithLaunchingOptions方法。我在各个论坛中与同一主题相关的一些帖子中看到,如果我们实现后一种(didfinishWithLaunchingOptions)方法,则不会调用handleOpenWithURL,是这样吗?
如果没有,您能帮我找出代码中的错误吗?我是这个领域的初学者,非常感谢您在这方面的帮助。
以下是appdelegate.m文件中的代码片段
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"Inside didfinishwithoptions");
DBSession* dbSession = [[[DBSession alloc] initWithAppKey:@"APP-KEY"
appSecret:@"APP-SECRET"
root:kDBRootAppFolder] // either kDBRootAppFolder or kDBRootDropbox
autorelease];
[DBSession setSharedSession:dbSession];
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSLog(@"Inside handleOpenURL");
return NO;
}
I am using MacOSX 10.6, and the Xcode simulator is 4.2, but after trying my best, handleOpenURL does not get called in my appdelegate.m file, where I have implemented it. I have followed all the instructions in the tutorial given in the DropBox site(DropBox Tutorial),
but, once a user allows my application to access, after loggin in from there dropbox account through safari, the control is redirected to my "Link with DropBox" view, i.e. the view from which the user gets the chance to log in,
The problem is, the handleOpenURL method is not called, and neither is the didfinishWithLaunchingOptions method called. I have seen in some posts in various forums related to the same topic, that if we implement the latter(didfinishWithLaunchingOptions) method, handleOpenWithURL will not called, is it so?
if not, can you please help me find out the error in my code.. I am a beginner in this field, and will really appreciate your help in this regard.
The following is the code snippet in the appdelegate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"Inside didfinishwithoptions");
DBSession* dbSession = [[[DBSession alloc] initWithAppKey:@"APP-KEY"
appSecret:@"APP-SECRET"
root:kDBRootAppFolder] // either kDBRootAppFolder or kDBRootDropbox
autorelease];
[DBSession setSharedSession:dbSession];
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSLog(@"Inside handleOpenURL");
return NO;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为当您将目标设置为 iOS 4.2 或更高版本时,不会调用
application:handleOpenURL:
。请改用application:openURL:sourceApplication:annotation:
。更多信息请参见 UIApplicationDelegate 文档。
更新:
您是否仔细检查了应用程序 plist 文件中的
CFBundleURLTypes
条目?它应该像这样:比你初始化会话(注意上面的“某事”部分用作应用程序密钥):
如果上面没有帮助,那么你一定做错了其他事情。然后更仔细地遵循 DropBox 的教程。
I think that
application:handleOpenURL:
is not called when you set target to iOS 4.2 or later. Useapplication:openURL:sourceApplication:annotation:
instead.More in UIApplicationDelegate docs.
UPDATE:
Did you double check your
CFBundleURLTypes
entry in your application's plist file? It should like something like that:Than you init the session (note that above "something" part is used as app key):
If above doesn't help, you must be doing wrong something else. Follow the DropBox's tutorial more carefully then.
如果 swift >= iOS 13 将以下函数添加到 SceneDelegate.swift 似乎可以工作:
In case of swift >= iOS 13 adding the following func to SceneDelegate.swift seems to work: