는 먼저, Mail.app 수동적는 자사의 Info.plist 파일에 다음을 포함하여 "흔한"URL 체계를 처리 서비스 시작 알려줍니다
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Email Address URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>mailto</string>
</array>
<key>LSIsAppleDefaultForScheme</key>
<true/>
</dict>
...
</array>
다음, 그것은 에 대한 핸들러를 설정/kAEGetURL
Apple 이벤트.
NSAppleEventManager* appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
당신은이 같은 핸들러 메소드 구현할 수 : 코코아, 그 뭔가처럼 보이는 "흔한"URL에 대한
- (BOOL)handleGetURLEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
NSAppleEventDescriptor* directObjectDescriptor = [event paramDescriptorForKeyword:keyDirectObject];
NSString* urlString = [directObjectDescriptor stringValue];
NSURL* url = [NSURL URLWithString:urlString];
// ... do something with url ...
}
을 NSURL
의 구문 분석 동작의 많은 부분이 있기 때문에 효과가 없습니다 URL이 RFC 1808을 준수하지 않습니다 (리소스 지정자가 "//"로 시작하지 않음). -resourceSpecifier
메서드를 사용하여 실제로는 scheme (mailto)과 리소스 지정자 만 가져올 수 있습니다. 일부 mailto URL은 "? subject = Some % 20subject % 20text"와 같은 검색어와 유사한 구문을 가질 수 있지만 NSURL
은 그 선택을 돕지 않습니다. 따라서 수동으로해야합니다. (자원 지정자 앞부분에 "//"을 삽입하여 가짜 URL을 구성하는 것을 고려해 볼 수 있으며 NSURL
은이를 구문 분석합니다.)
대단히 고마워요! –