Airdrop: making a custom URL scheme be less ugly for recipient

自古美人都是妖i 提交于 2019-12-08 12:46:20

问题


I'm using Airdrop to send a custom URL to cause my app to open on the other device with the relevant info.

It works fine, but it looks really ugly on the receiving device, because they receive a message that quotes the URL as thing being sent, for example schemename://123456. Is there any way to either make the message look nicer, or get the receiving device to tell you which app it wants to open the information in, rather than showing the cryptic looking URL?


回答1:


Make a custom object that confirms with the UIActivityItemSource

 @interface LAAirDropCustomUrl : NSObject <UIActivityItemSource>

 @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;
  }



回答2:


This Eventbrite engineering post describes a potential way of achieving your intended task.

There is a sample project attached to the post https://engineering.eventbrite.com/setting-the-title-of-airdrop-shares-under-ios-7/

Quick summary for the post:

Save the URL in file with a custom extension (file type) that can only be opened by your app. The Airdrop recipient will open the file in your app if they have it installed or will be asked to install your app from the AppStore.



来源:https://stackoverflow.com/questions/20216100/airdrop-making-a-custom-url-scheme-be-less-ugly-for-recipient

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