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
MZaragoza
  • 10,108
  • 9
  • 71
  • 116
Fred Zhang
  • 115
  • 1
  • 2
  • 8
  • Have you tried any of the other legal values for the activation rule? – Tom Harrington Jan 12 '15 at 20:49
  • Yes, I try other all the legal attributes: NSExtensionActivationSupportsFileWithMaxCount 100 NSExtensionActivationSupportsMovieWithMaxCount 100 NSExtensionActivationSupportsText YES NSExtensionActivationSupportsWebPageWithMaxCount 100 NSExtensionActivationSupportsWebURLWithMaxCount 100 – Fred Zhang Jan 13 '15 at 01:54

1 Answers1

17

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
Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • @Tom: Is there any way i can give a max limit to count like NSExetnsionActivationSupportsWebPageWithMaxCount .@count only works on .@count == 1 and .@count >=1. Can i give something like .@count <= 10. – Arun Gupta Mar 30 '15 at 11:21