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

2

0

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?

Dignity answered 26/11, 2013 at 11:40 Comment(0)
R
2

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;
  }
Restful answered 26/11, 2013 at 11:50 Comment(4)
Brilliant, thanks, I should have looked more closely at the activity source protocol!Dignity
Just waiting to see if anyone else has any input first.Dignity
@Dignity can you post the UIActivityViewController code you used with the answer above for 50+ reputation on this question please: #20223607Statvolt
Sorry, had to just unaccept, as the answer doesn't actually let me do what I desire (see my question). I accepted prematurely!Dignity
B
0

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.

Benevolence answered 9/5, 2014 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.