I'm getting the following result when I try to initialize the Messenger component of UIActivityViewController:
I'm using this code to instantiate my UIActivityViewController:
NSString *textToShare = #"Text that will be shared";
NSArray *itemsToShare = [[NSArray alloc] initWithObjects:textToShare, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = [[NSArray alloc] initWithObjects: UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypePostToWeibo,UIActivityTypePostToFacebook,UIActivityTypePostToTwitter, nil];
[activityVC setValue:#"My Subject Text" forKey:#"subject"];
[self presentViewController:activityVC animated:YES completion:nil];
I then get the following error in my logs when I attempt to send with Message
Launch Services: Unable to find app identifier com.apple.MobileSMS
2013-07-31 01:27:15.180 Coolist[54111:c07] Application tried to push a nil view controller on target <MFMessageComposeViewController: 0xa38db30>.
Is this just a simulator problem?
Related
I use to use UIDocumentInteractionController and UIActivityViewController to share data with a special UTI.
However, when other app use Share Extension, there will may options when share interface popup, such as copy tp xxx and import to xxx.
How can i disable those options or is there any other way can share data to Specified app which i can control.
//=======
my code is like this:
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:#[itemUrl] applicationActivities:nil];
activity.excludedActivityTypes = #[UIActivityTypePostToFacebook, UIActivityTypePostToFacebook,UIActivityTypePostToWeibo,
UIActivityTypeMessage, UIActivityTypeMail, UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr, UIActivityTypePostToFlickr, UIActivityTypePostToFlickr,
UIActivityTypeAirDrop];
[self presentViewController:activity animated:YES completion:NULL];
Create a Array and add types which don't want to show to user, like this
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypeCopyToPasteboard];
Create a instance of UIActivityViewController
And set following propery
activityViewController.excludedActivityTypes = excludeActivities
I found out if you share as NSURL, you will get copy to xxx or import to xxx, but if you share as UIImage, you will not get that.
will show import to xxx
avc = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:fileURL, nil] applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];
will not show
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:fileURL]];
avc = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:image, nil] applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];
I am using ActivityViewController for sending mail from App.
I was able to auto fill subject and body but not participants.
Example code :
NSURL *recipients = [NSURL URLWithString:#"mailto:foo#bar.com"]; //Not working
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:#[recipients, #"bodyText"]
applicationActivities:nil];
[activityViewController setValue:mailSubject forKey:#"Subject"];
activityViewController.excludedActivityTypes = #[UIActivityTypeMessage, UIActivityTypePostToFacebook, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo, UIActivityTypePostToWeibo];
[self.navigationController presentViewController:activityViewController
animated:YES
completion:^{
}];
MailTo participants is not working.
When i run the code, pop up is coming with selected mail app but to field is empty.
I integrated a sharing option into my app and everything seems fine, basically I excluded every type of UIActivity except for Message, Twitter, and Facebook, and when I tested to see if it functions, what I see in the text box is
"I got a new highscore!
com.apple.UIKit.activity.Message
com.apple.UIKit.activity.PostToFacebook
com.apple.UiKit.activity.PostToTwitter".
and the text appears in each of activities.
Is there anyway to remove the text, or is it supposed to be that way?
Here is a method in my MainViewController which presents the UIActivityViewController.
-(void)sharedView {
APActivityProvider *APActivityPro = [[APActivityProvider alloc] init];
NSArray *activites = #[APActivityPro,UIActivityTypeMessage, UIActivityTypePostToFacebook, UIActivityTypePostToTwitter];
activityController = [[UIActivityViewController alloc] initWithActivityItems:activites applicationActivities:nil];
activityController.excludedActivityTypes = #[UIActivityTypePostToWeibo,
UIActivityTypeMail,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
UIActivityTypeAirDrop];
[self presentViewController:activityController animated:YES completion:nil];
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed)
{
if (completed)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:NSLocalizedString(#"Post Sent!",#"the confirmation of the sent message/post")
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK",#"done")
otherButtonTitles:nil];
[alert show];
}
}
];
}
And also my code in my APActivityProvider.m file.
-(id) activityViewController:(UIActivityViewController*)activityViewController
itemForActivityType:(NSString *)activityType
{
if ([activityType isEqualToString:UIActivityTypeMessage])
return NSLocalizedString(#"I got a new highscore!",#"Comment for message");
if ([activityType isEqualToString:UIActivityTypePostToFacebook])
return NSLocalizedString(#"I got a new highscore!",#"Comment for Facebook");
if ([activityType isEqualToString:UIActivityTypePostToTwitter])
return NSLocalizedString(#"I got a new highscore!",#"Comment for twitter");
return nil;
}
- (id) activityViewControllerPlaceholderItem:(UIActivityViewController *)
activityViewController
{
return #"";
}
It would appear you are using the API incorrectly. Specifically:
NSArray *activites = #[APActivityPro,UIActivityTypeMessage, UIActivityTypePostToFacebook, UIActivityTypePostToTwitter];
activityController = [[UIActivityViewController alloc] initWithActivityItems:activites applicationActivities:nil];
Activity Items are your content (Strings, Images, etc) while applicationItems are the custom activity options you add to the default system ones (something you code such as an open in app store activity). You do not need to tell the UIActivityViewController what system activities you want. All are enabled by default.
For an example of how to use this API, I have included the following:
NSNumber *AppStoreID = [NSNumber numberWithInt:550008982];
NSArray *activityItems =
#[ AppStoreID ];
NSArray *applicationActivities =
#[ [ATFAppStoreActivity alloc] ];
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
[self presentViewController:activityViewController animated:YES completion:nil];
Here, I have my subclassed UIActivity (ATFAppStoreActivity) that takes an NSNumber to display the App Store page for that app.
I've set up my UIActivityViewController and mail shows up. But I can't figure out how to get Facebook/Twitter to work? I have read somewhere that since obviously the Xcode doesn't have Facebook/Twitter signed in, iOS7 doesn't show the app?
My code:
NSArray *activityItems = #[#"Hello"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact ];
[self presentViewController:activityViewController animated:YES completion:NULL];
Include facebook, twitter, message, email and so on ,like this:
In your ViewController.m :
NSString *message = #"The Flyer http://flyerdream.tumblr.com";
UIImage *image = [UIImage imageNamed:#"flyer"];
NSArray *arrayOfActivityItems = [NSArray arrayWithObjects:message, image, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:arrayOfActivityItems applicationActivities:nil];
[self.navigationController presentViewController:activityVC animated:YES completion:nil];