本文介绍了Airdrop:为收件人制作自定义URL方案不那么难看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Airdrop发送自定义网址,以使我的应用在其他设备上打开并显示相关信息。

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

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

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?

推荐答案

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

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

这篇关于Airdrop:为收件人制作自定义URL方案不那么难看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:25
查看更多