Airdrop:为收件人制作自定义URL方案不那么难看

我正在使用Airdrop发送自定义url,以便在其他设备上使用相关信息打开我的应用。

它工作正常,但在接收设备上看起来真的很难看,因为它们收到一条消息,引用URL作为发送的东西,例如schemename://123456 。 有没有办法让消息看起来更好,或让接收设备告诉你想要打开信息的应用程序,而不是显示神秘的URL?

创建一个使用UIActivityItemSource确认的自定义对象

  @interface LAAirDropCustomUrl : NSObject  @property (strong, nonatomic) NSURL *url; @property (strong, nonatomic) UIImage *productImage; - (id)initWithUrl:(NSURL *)url; @end @implementation LAAirDropCustomUrl - (id)initWithUrl:(NSURL *)url { if (self = [super init]) { _url = url; } return self; } #pragma mark - UIActivityItemSource - (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController { //Because the URL is already set it can be the placeholder. The API will use this to determine that an object of class type NSURL will be sent. return self.url; } - (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType { //Return the URL being used. This URL has a custom scheme (see ReadMe.txt and Info.plist for more information about registering a custom URL scheme). if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { return nil; } else { if ([activityType isEqualToString:UIActivityTypeAirDrop]) { return self.url; } } return nil; } - (UIImage *)activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size { //Add image to improve the look of the alert received on the other side, make sure it is scaled to the suggested size. return self.productImage; } 

这个Eventbrite工程文章描述了实现预期任务的潜在方式。

有一个示例项目附在posthttps://engineering.eventbrite.com/setting-the-title-of-airdrop-shares-under-ios-7/

post的快速摘要:

使用只能由您的应用打开的自定义扩展程序(文件类型)将URL保存在文件中。 Airdrop收件人将在您的应用程序中打开该文件,如果他们安装了该文件,或者将要求他们从AppStore安装您的应用程序。