Email issue iOS8 in Simulator - ios

I have an issue in iOS8 issue in Simulator in won't work ? can anybody help me for this ?
here message is String Message but it not appear in Mail sheet ?
Here's what i have tried !!
NSMutableString* sub = [NSMutableString string];
[message appendFormat:#"\n"];
[sub appendString:#"Item Id : "];
[sub appendString:item.item_id];
UIImage *img = self.thumbnailImageView.image;
NSMutableArray *actItems = [[NSMutableArray alloc] init];
[actItems addObject:message];
[actItems addObject:sub];
if(img != nil)
{
[actItems addObject:img];
}
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:actItems
applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePostToFacebook,
UIActivityTypePostToTwitter,
UIActivityTypeAirDrop];
[self.navigationController presentViewController:activityViewController
animated:YES
completion:^{}];
[activityViewController setValue:sub forKey:#"subject"];
activityViewController.popoverPresentationController.sourceView = parentView;

Related

UIActivityViewController not working on iPad? iOS 8

I've followed suggestions from similar SO questions and can't seem to make this work. I'm working on a game, which reports the last score and then a share button for that last score.
This works on iPhone and my code for the iPad as shown below doesn't. The iPad version just crashes as soon as I hit the Share button. This code was from this tutorial on Coding Explorer.
iPad code (doesn't work)
- (IBAction)shareButton:(id)sender;
{
NSString * text = [NSString stringWithFormat:#"I just scored %li in Flying Freddy. Think you can beat it? https://itunes.apple.com/app/id1033007818", (long)_score];
NSArray *objectsToShare = #[text];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}
iPhone code (does work)
- (IBAction)ShareIt {
NSString * text = [NSString stringWithFormat:#"I just scored %li in Flying Freddy. Think you can beat it? https://itunes.apple.com/app/id1033007818", (long)_score];
NSArray * activityItems = #[text];
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
avc.excludedActivityTypes = #[ UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:avc animated:YES completion:nil];
}
You must add a source view.
Try to add this line :
activityVC.popoverPresentationController.sourceView = self.view;
You can also add the arrow direction :
activityVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionRight;
activityVC.popoverPresentationController.sourceView = sender;
I also had to set the modalPresentationStyle, preferredContentSize and sourceRect for the Pipiks answer to work.

MFMessageComposeViewController freezes before displaying the view controller

I'm having a problem where every time I click the button that calls on my MFMessageComposeViewController nothing happens. More specifically it freezes before it displays the controller and I am not able to do anything.
Here's my code:
- (IBAction)getQuote:(id)sender {
NSString * inputProduct =_productTextField.text;
NSString * inputYear = _yearTextField.text;
NSString * inputMake = _makeTextField.text;
NSString * inputEmail = email.text;
NSString * inputDescript = _descript.text;
emailConfirmation.text = email.text;
//email subject
NSString *emailTitle = #"Love Shack Electronics";
//email content
if ([conditionlabel isEqual: #"Fair"]) {
NSString *emailBody = [NSString stringWithFormat:#"Product:%# Make:%# Year Manufactured:%# Description:%# Condition:Fair Email:%#",inputProduct,inputMake,inputYear,inputDescript, inputEmail];
NSArray *recipient = [NSArray arrayWithObject:#"LoveShackElectronics#gmail.com"];
MFMailComposeViewController *SuperLovedEmail = [[MFMailComposeViewController alloc]init];
[SuperLovedEmail setTitle:emailTitle];
[SuperLovedEmail setToRecipients:recipient];
[SuperLovedEmail setMessageBody:emailBody isHTML:NO];
[SuperLovedEmail setUserActivity:false];
[self presentViewController:SuperLovedEmail animated:YES completion:nil];
[SuperLovedEmail setEditing:false];
If anyone can help or figure out what is wrong with my code it would be greatly appreciated.
Please check in device and latest Xcode version. it's work fine. it not work then put into dispatch method like below
dispatch_async(dispatch_get_main_queue(),
^{
if ([conditionlabel isEqual: #"Fair"])
{
NSString *emailBody = [NSString stringWithFormat:#"Product:%# Make:%# Year Manufactured:%# Description:%# Condition:Fair Email:%#",inputProduct,inputMake,inputYear,inputDescript, inputEmail];
NSArray *recipient = [NSArray arrayWithObject:#"LoveShackElectronics#gmail.com"];
MFMailComposeViewController *SuperLovedEmail = [[MFMailComposeViewController alloc]init];
[SuperLovedEmail setTitle:emailTitle];
[SuperLovedEmail setToRecipients:recipient];
[SuperLovedEmail setMessageBody:emailBody isHTML:NO];
[SuperLovedEmail setUserActivity:false];
[self presentViewController:SuperLovedEmail animated:YES completion:nil];
[SuperLovedEmail setEditing:false];
}
});

iOS share button crashing when run on ipad

I am working on a xcode project in objective-c and i want a share button on my ios application to share things i watched a tutorial on youtube here's the link : https://www.youtube.com/watch?v=zkrOKN_OA_A
but when i run this code on iphone it works properly and when i run this code on ipad the xcode give's me this error :
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}}
I used this code :
- (IBAction)Share1:(id)sender {
UIImage *shareImage = [UIImage imageNamed:#"invoice_logo.png"];
NSArray *itemsToShare = #[shareImage];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[];
[self presentViewController:activityVC animated:YES completion:nil];}
You are missing :
activityVC.excludedActivityTypes=#[UIActivityTypePostToFacebook,UIActivityTypePostToTwitter]// add your share types
look at the video you provided from 7:30 min
Try this:
UIImage *shareImage = [UIImage imageNamed:#"invoice_logo.png"];
NSArray *itemsToShare = #[shareImage];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.popoverPresentationController.sourceView = self.view;
activityVC.popoverPresentationController.sourceRect =
CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height-50, 1.0, 1.0);
[self presentViewController:activityVC animated:YES completion:nil];

Why MailController doesn't show To and Body text?

I have this code on Objective-C:
- (IBAction)Mail:(id)sender {
NSString *MailTitle = #"Mi Opinion About this App";
NSString *MailBody = #"Hi, I am an user of this app and I think that ";
NSArray *MailTo = [NSArray arrayWithObject:#"contact#domain.com"];
MFMailComposeViewController *MailController = [[MFMailComposeViewController alloc] init];
MailController.mailComposeDelegate = self;
[MailController setSubject:MailTitle];
[MailController setMessageBody:MailBody isHTML:NO];
[MailController setToRecipients:MailTo];
[self presentViewController:MailController animated:YES completion:NULL];
}
It shows properly the subject, but the fields "To", and "Body" are empty in iOS simulator!

UIActivityViewController issue iOS 7 and iOS 8?

I’m building an article reading app for iPad. I have integrated a social sharing functionality which means user can share articles on Facebook, and google mail.
I’m using UIActivityViewController for sharing.
There is a bar button item,when user click on that UIActivityViewController opens.I updated Xcode 6
When I run on simulator it runs fine But I run on real device(iPad) with iOS 7,the app get crash on clicking on bar button item.
this is my code:
- (IBAction)ysshareAction:(id)sender
{
NSURL *linkURL = [NSURL URLWithString:_DetailModal1[4]];//article url
NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:_DetailModal1[0]];//_DetailModal1[0] contain article title////
[stringText addAttribute:NSLinkAttributeName value:linkURL range:NSMakeRange(0, stringText.length)];
NSArray * itemsArray = #[[NSString stringWithFormat:#"%#",_DetailModal1[0]], [NSURL URLWithString:_DetailModal1[4]]];
NSArray * applicationActivities = nil;
UIActivityViewController * AVC = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];
AVC.popoverPresentationController.sourceView = _webView;
[self presentViewController:AVC animated:YES completion:nil];
[AVC setCompletionHandler:^(NSString *act, BOOL done)
{
if([act isEqualToString:UIActivityTypeMail]) {
ServiceMsg = #"Mail sent!";
} else if([act isEqualToString:UIActivityTypePostToTwitter]) {
ServiceMsg = #"Article Shared!";
} else if([act isEqualToString:UIActivityTypePostToFacebook]) {
ServiceMsg = #"Article Shared!";
} else if([act isEqualToString:UIActivityTypeMessage]) {
ServiceMsg = #"SMS sent!";
} else if([act isEqualToString:UIActivityTypeAddToReadingList]) {
ServiceMsg = #"Added to Reading List";
} else if([act isEqualToString:UIActivityTypeCopyToPasteboard]){
ServiceMsg = #"Copied Link";
}
if ( done )
{
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:#"" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil];
[Alert show];
}
}];
}
Help is appreciated!
Following line is the issue
AVC.popoverPresentationController.sourceView = _webView;
You will have to put iOS8 condition in order popoverPresentationController is introduced for iOS 8 and later so you can not use it with iOS 7
For checking for iOS8 you can define a macro like found from here
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
And use it in following way.
NSURL *linkURL = [NSURL URLWithString:_DetailModal1[4]];//article url
NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:_DetailModal1[0]];//_DetailModal1[0] contain article title////
[stringText addAttribute:NSLinkAttributeName value:linkURL range:NSMakeRange(0, stringText.length)];
NSArray * itemsArray = #[[NSString stringWithFormat:#"%#",_DetailModal1[0]], [NSURL URLWithString:_DetailModal1[4]]];
NSArray * applicationActivities = nil;
UIActivityViewController * AVC = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0")){
AVC.popoverPresentationController.sourceView = _webView;
}
[self presentViewController:AVC animated:YES completion:nil];
Refer this for more info about what has changed for UIActivityViewController in iOS8
A lot might argue that checking for existence of the class explicitly is better than checking a hard coded version number. UIPopoverPresentationController may be deprecated at some future point, or there might be a (future ?) device which does not support the class, like the iPhone never used to support UIPopoverController or UISplitViewController..
if ( NSClassFromString(#"UIPopoverPresentationController") ) {
AVC.popoverPresentationController.sourceView = _webView;
}
In Swift, You can use '?' instead checking OS version.
AVC.popoverPresentationController?.sourceView = _webView

Resources