2012-07-25 40 views
0

我已經爲我的應用添加了一個URL方案,並且它在點擊鏈接「my_scheme:// item_to_add」時打開(或者如果已經打開,則被重新打開)。從Cocoa中的URL方案中捕獲URL

我發現如何捕捉在iOS上的鏈接:

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

任何人都可以點我到Mac,在那裏我將能夠捕捉到鏈路上的類似的方法?

回答

1

好了,找到了自己的答案再次;)

//Register to the AppleEventManager 
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; 
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; 

而實施選擇方法:

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:  (NSAppleEventDescriptor *)replyEvent 
{ 
    NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; 
    NSLog(@"%@", url); 
}