Reputation: 5301
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:
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?
Upvotes: 3
Views: 8010
Reputation: 1405
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.
Upvotes: 3
Reputation: 9006
You should use NSURL
object instead of NSString
when you want an element to be treated as a URL. Replace:
NSArray *activityItems = @[self.title, urlString];
with
NSArray *activityItems = @[self.title, [NSURL URLWithString:urlString]];
Then follow @Santa Claus's advice if you want elements other than Add to Reading List
to be visible.
Upvotes: 1
Reputation: 15377
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).
Upvotes: 4