5

My next problem is the following: I have an app that shares via AirDrop a custom URL scheme:

    NSMutableString *mutableString = [NSMutableString stringWithString:@"appName://"];
    [mutableString appendString:contentProduct.url];
    NSURL *airDropUrl = [[NSURL alloc] initWithString:mutableString];
    LAAirDropCustomUrl *customUrlSCHEMA = [[LAAirDropCustomUrl alloc] initWithUrl:airDropUrl];
    NSArray *activityItems = [NSArray arrayWithObjects:customUrlSCHEMA, nil];
    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                                                                     applicationActivities:nil];

I've added the URL scheme in the Info section of the project's target, and sharing via AirDrop works just fine. On the other hand, if the other device does not have the app, a default alert is shown, stating that "the device x is trying to share smth on an app that you don't have, wanna go get from appstore?". I would like that, if the other device does NOT have the app, to send a different URL that a browser could open.

If I'm trying to add default NSURL* among the activityItems, I'm getting a error saying that "the device x cannot receive these kind of items"

    NSURL *airDropUrl = [[NSURL alloc] initWithString:mutableString];        
    NSArray *activityItems = [NSArray arrayWithObjects:airDropUrl,customUrlSCHEMA , nil];

The LAAirDropCustomUrl implementation is:

- (id)initWithUrl:(NSURL *)url {
     if (self = [super init]) {
         _url = url;
     }
     return self;
 }

 - (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
     return self.url;
 }

 - (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {

     if ([activityType isEqualToString:UIActivityTypeAirDrop]) {
         return self.url;
     }
     return  nil;
  }
Durican Radu
  • 1,327
  • 11
  • 12

1 Answers1

0

Unfortunately you cannot accomplish what you are trying to do here with the current APIs. If you feel this is an omission, you should file a bug with Apple requesting this capability.

The error "the device x cannot receive these kind of items" is shown whenever an app is trying to share a mixture of items. As an example, this error alert would show when an app tries to share a PDF and Pages document at the same time. Same goes for mixed url schemes, which is what is happening in your case (http://some-url.com and appName://some-custom-url).

ccjensen
  • 4,578
  • 2
  • 23
  • 25