title: Sharing images/videos to other apps through UIActivityViewController shows shared items twice in iOS
body: <p>I'm trying to share some images and videos to other apps(like FB, WhatsApp) using <code>UIActivityViewController</code>. I have sub-classed <code>UIActivityItemProvider</code>, and on calling <code>-(id)item</code> methods, I'm processing the images/videos and saving in documents directory. Then I am returning the file paths as <code>NSURLs</code>. My problem is that <strong>I'm not able to find a way to send multiple file URLs at the same time.</strong></p>
  
  <p>Below are the approaches I took to return urls from -(id)item method;</p>
  
  <ol>
  <li>As an <code>NSArray</code> of <code>NSURL</code> objects. DOES NOT WORK. When the target app popup comes, it is empty always.</li>
  <li>As a <code>NSDictionary</code>, in which <code>NSURL</code> objects are the values and keys could be anything. PROBLEMATIC: The target app popup shows all items, but TWICE! I experimented with the dictionary a lot, but couldn't find a way to solve this.</li>
  </ol>
  
  <p>Simply returning an <code>NSURL</code> object from <code>-(id)item</code> method works fine for single file. But, I have to share multiple items. Array doesn't work, Dictionary is duplicating shared items.</p>
  
  <p>Can someone please tell me what I'm doing wrong here?</p>
  
  <hr>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>This is how I show the UIActivityViewController.</p>
  
  <pre><code>CustomItemProvider *provider = [[CustomItemProvider alloc] initWithPlaceholderItem:[UIImage imageNamed:@"ios-59.png"]];
  
  UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[provider] applicationActivities:nil];
  
  activityViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError)
  {
      if(completed)
      {
          NSLog(@"Activity Completed");
      }
      else
      {
          NSLog(@"Activity Cancelled");
      }
  };
  [self presentViewController:activityViewController animated:YES completion:^{}];
  </code></pre>
  
  <p>The UIActivityItemProvider implementation is as given below; The URLs are valid and there are images/videos at those locations.</p>
  
  <pre><code>@interface CustomItemProvider : UIActivityItemProvider
  
  @end
  
  @implementation CustomItemProvider
  - (id)item
  {
       NSURL *url1 = [NSURL fileURLWithPath:@"file one url"];
       NSURL *url2 = [NSURL fileURLWithPath:@"file two url"];
       NSURL *url3 = [NSURL fileURLWithPath:@"file three url"];
  
       return @{@"item1":url1, @"item2":url2, @"item3":url3};    //As NSDictionary. This causes 6 items to be shared; all files twice.
  
       //return @[url1, url2, url3];  //As NSArray
  }
  @end
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>The linked question is different.
  I don't want to send the files directly to the UIActivityViewController as parameter to <code>initWithActivityItems:</code>. The reason is that there could be multiple video files, which will cause memory warning and a crash. Also, I will be manipulating the files before sending it to target app(in the <code>-(id)item</code> method, which I have not shown here), hence I need <code>UIActivityItemProvider</code> to process the files in background.</p>