3

I want to add share extension on Apple's Maps, does anyone know how to do. I try to set NSExtensionAttributes as below but it don't work, my APP doesn't show in the Maps's share sheet.

NSExtensionAttributes

NSExtensionActivationRule
  NSExetnsionActivationSupportsWebURLWithMaxCount
  NSExetnsionActivationSupportsWebPageWithMaxCount
4

1 回答 1

16

我不确定为什么NSExtensionActivationSupportsText不能与地图一起使用,但是当我尝试时我得到了相同的结果。

您需要的是更复杂的激活规则。将激活规则的类型设置为“字符串”,并使用App Extension Programming GuideSUBQUERY中描述的格式设置值。当您这样做时,您可以请求一个或多个特定的尿路感染。地图将提供纯文本 ( ),它应该等同于但显然不是。它还提供了位置卡 ( ) 和 URL ( )。public.plain-textNSExtensionActivationSupportsTextpublic.cardpublic.url

由 UTI 检查任何这些的激活规则看起来像

SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.plain-text").@count >= 1).@count >= 1 OR SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, SUBQUERY($attachment.registeredTypeIdentifiers, $uti, $uti UTI-CONFORMS-TO "public.url" AND NOT $uti UTI-CONFORMS-TO "public.file-url").@count >= 1).@count >= 1).@count >= 1 OR SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.vcard").@count >= 1).@count >= 1

这只是SUBQUERY检查每个 UTI 的三个子句,或一起检查。

根据您可以处理的数据,您可能希望减少它以仅涵盖您的扩展程序知道如何处理的 UTI。例如,如果您想要的只是 URL,则只使用该部分:

SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, SUBQUERY($attachment.registeredTypeIdentifiers, $uti, $uti UTI-CONFORMS-TO "public.url" AND NOT $uti UTI-CONFORMS-TO "public.file-url").@count >= 1).@count >= 1).@count >= 1

此版本仅检查您获取的 URL 不是文件 URL。

Maps 提供了一个 Apple Maps URL,类似于http://maps.apple.com/?q=37.332331,-122.031219&sll=37.332331,-122.031219

如果您使用 vcard UTI,您将获得NSString编码为NSData. 如果你解码它,它看起来像这样:

BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//iOS 8.2//EN
N:;Shared Location;;;
FN:Shared Location
item1.ADR;type=HOME;type=pref:;;;;;;
item2.URL;type=pref:http://maps.apple.com/?q=37.332331\,-122.031219&sll=37.332331\,-122.031219
item2.X-ABLabel:map url
END:VCARD
于 2015-01-13T22:36:47.387 回答