iOS add share extension on maps

亡梦爱人 提交于 2019-12-03 03:56:27

I'm not sure why NSExtensionActivationSupportsText doesn't work with Maps, but I get the same result when I try.

What you need is a more complex activation rule. Set the type of the activation rule to "string", and set up the value using the SUBQUERY format described in the App Extension Programming Guide. When you do that you can request one or more specific UTIs. Maps will provide plain text (public.plain-text), which should be equivalent to NSExtensionActivationSupportsText but apparently is not. It also provides a location card (public.card) and a URL (public.url).

An activation rule that checks for any of these by the UTIs would look like

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

That's just three SUBQUERY clauses that check for each of those UTIs, OR-ed together.

Depending on what data you can handle, you might want to reduce that to cover only UTIs that your extension knows how to deal with. For example if all you want is the URL, only use that part:

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

This version just checks that you're getting a URL which is not a file URL.

Maps provides an Apple Maps URL which will be something like http://maps.apple.com/?q=37.332331,-122.031219&sll=37.332331,-122.031219

If you use the vcard UTI, you'll get an NSString encoded into an NSData. If you decode it, it looks something like this:

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!