我開始第一次嘗試製作mac應用程序,並且業務的第一順序是使用OAuth和Soundcloud對應用程序進行身份驗證。發送授權請求很簡單,但是我堅持的是如何從Soundcloud收聽重定向。如何聆聽原生可可應用程序的OAuth2重定向uri
我已經在info.plist中設置了我的URL方案,並將我的應用程序設置爲偵聽傳入請求,但是當我嘗試註冊時,我沒有得到響應。我已經用safari測試過這個網址,它運行良好。
這裏的代碼片斷從我的應用程序的委託:
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
[[NXOAuth2AccountStore sharedStore] setClientID:@"myClientID"
secret:@"superSecretSecret"
authorizationURL:[NSURL URLWithString:@"https://soundcloud.com/connect"]
tokenURL:[NSURL URLWithString:@"https://api.soundcloud.com/oauth2/token"]
redirectURL:[NSURL URLWithString:@"myApp://connect"]
forAccountType:@"iHopeThisWorks"];
}
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
}
我的猜測是,的SoundCloud不知道在哪裏可以找到對myApp://連接,因爲它只是我的本地機器上存在。那麼,我是否需要創建一些中介,如處理http請求的Web服務?如果是這樣,中介如何知道如何連接到我的機器?很抱歉,如果這些是基本或誤導性的問題,但正如我之前所說的,這是我第一次發現類似這樣的情況,而我的谷歌搜索功能使我找不到解決方案。