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?

occulus
  • 16,959
  • 6
  • 53
  • 76

2 Answers2

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;
  }
Durican Radu
  • 1,327
  • 11
  • 12
  • Brilliant, thanks, I should have looked more closely at the activity source protocol! – occulus Nov 26 '13 at 12:05
  • Just waiting to see if anyone else has any input first. – occulus Nov 26 '13 at 12:11
  • @occulus can you post the UIActivityViewController code you used with the answer above for 50+ reputation on this question please: http://stackoverflow.com/questions/20223107/customize-the-airdrop-alert-description?noredirect=1#comment30270040_20223107 –  Nov 29 '13 at 19:17
  • Sorry, had to just unaccept, as the answer doesn't actually let me do what I desire (see my question). I accepted prematurely! – occulus Nov 30 '13 at 14:16
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.

Marius Ciocanel
  • 151
  • 1
  • 6