Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController In iOS 7 Missing Options

I was using the following code with iOS 6 SDK to implement UIActivityViewController:

-(IBAction)Share:(id)sender
{    
    NSArray *activityItems = @[self.title, urlString];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];

      [self presentViewController:activityVC animated:YES completion:nil];


    [activityVC setCompletionHandler:^(NSString *activityType, BOOL completed)
     {
         NSLog(@"Activity = %@",activityType);
         NSLog(@"Completed Status = %d",completed);

         if (completed)
         {
             UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Successfully Shared" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [objalert show];
             objalert = nil;
         } else
         {
             UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Unable To Share" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [objalert show];
             objalert = nil;
         }
     }];
}

The above code in iOS 7 is giving me the following output:

ios share facebook twitter uoactivityviewcontroller

Earlier there wasn't Facebook and Twitter in the share sheet but i signed into both both these apps in the Settings and Facebook and Twitter started appearing.

PROBLEM: Belo the line, there is only COPY and other like BOOKMARK, ADD TO READING LIST, ADD TO HOMESCREEN, PRINT and AirDrop buttons are not showing up. What can i do to bring these? Thanks!

UPDATE: I have added the print button by using one answer below, how can i add the rest?

like image 817
AJ112 Avatar asked Dec 06 '25 20:12

AJ112


2 Answers

Bookmark, Add To Reading List, and Add To Homescreen are only available in safari, unless you define them yourself. To add those buttons, you need to create an applicationActivities NSArray, populated with UIActivity objects for various services. You can pass this array into the initWithActivityItems:applicationActivities: UIActivityViewController method (you were passing nil for this parameter).

like image 114
Andrew Avatar answered Dec 09 '25 13:12

Andrew


You should use UISimpleTextPrintFormatter to show PRINT:

UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
                                             initWithText:self.title];
NSArray *activityItems = @[self.title, printData];

Follow @Arkadiusz Holko and @Santa Claus answers to add another functionality.

like image 39
Numeral Avatar answered Dec 09 '25 15:12

Numeral