0

CocoaSoundCloudAPI を使用して、Cocoa で OSX 用の基本的なデスクトップ アプリを作成しようとしています。

認証に苦労しています。ログイン ボタンをクリックすると、アプリの認証を試みる外部ブラウザ ウィンドウが開きます。「接続」をクリックすると、接続ボタンに素敵なアニメーションが表示されます...永遠に、[SCSoundCloud account]nullです。

ただし、このプロセス中に外部ブラウザ ウィンドウで [キャンセル] をクリックすると、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をガイドとして使用してきましたが、ほとんどのものが機能することがわかりました。誰かが私を正しい方向に押し進めることができますか?

4

1 に答える 1

0

NSLogging を実行したところ、実際には、有効な SoundCloud Account オブジェクトを受信して​​いたことがわかりました。オブジェクトを受信するには、もう少し時間が必要でした。

しかし、接続が完了したことを示す通知を外部ブラウザ ウィンドウが受け取っていないことに驚きました。


アプリで Facebook 認証を使用しても、ブラウザ ページで認証が完了したという通知が表示されないようです。どうすればこれを達成できるか知っている人はいますか?コールバック URL が正しいことは確かですが、引き続き試してみます...

于 2013-10-18T01:35:28.440 に答える