我一直在尝试使用 CocoaSoundCloudAPI 在 Cocoa 中为 OSX 创建一个基本的桌面应用程序。
我正在努力进行身份验证。单击登录按钮会打开一个外部浏览器窗口,该窗口尝试对我的应用程序进行身份验证。如果我单击“连接”,连接按钮会显示一个可爱的动画......永远,并且[SCSoundCloud account]
是空的。
但是,如果我在此过程中单击外部浏览器窗口中的“取消”,我会看到 SCAccount 变为!nil
谁能解释一下?
这是我的代码:
#import "SCMAppDelegate.h"
@implementation SCMAppDelegate
+ (void)initialize
{
[SCSoundCloud setClientID:@"MYID"
secret:@"MYSECRET"
redirectURL:[NSURL URLWithString:@"sampleproject1://oauth"]];
}
- (IBAction)login:(id)sender
{
[SCSoundCloud requestAccessWithPreparedAuthorizationURLHandler:^(NSURL *preparedURL){
// Load the URL in a web view or open it in an external browser
[[NSWorkspace sharedWorkspace] openURL:preparedURL];
}];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
{
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(handleURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
}
- (void)handleURLEvent:(NSAppleEventDescriptor*)event
withReplyEvent:(NSAppleEventDescriptor*)replyEvent;
{
NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
BOOL handled = [SCSoundCloud handleRedirectURL:[NSURL URLWithString:url]];
if (!handled) {
NSLog(@"The URL (%@) could not be handled by the SoundCloud API. Maybe you want to do something with it.", url);
}
NSLog(@"This is the account: %@", [SCSoundCloud account]);
}
@end
我一直在使用https://github.com/soundcloud/CocoaSoundCloudAPI/blob/master/GeneralUsage.md作为指南,并且发现大多数事情都可以工作。谁能把我推向正确的方向?