MFMailComposeViewController not working iOS 9 - xcode

I am using xcode 7.3 and using following code to open MfMailComposeViewController and object of mail composer goes nil after alloc init it.
- (void)openMailComposer {
NSString *emailTitle = #"Invite for SpotFit";
MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
mailVC.mailComposeDelegate = self;
[mailVC setSubject:emailTitle];
[mailVC setMessageBody:AppLink isHTML:NO];
[self presentViewController:mailVC animated:NO completion:nil];
}
Please provide any solution for it.

Related

ALAssetsLibrary writeImageToSavedPhotosAlbum block the program in iOS8

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSMutableDictionary* meta = [[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
UIImage* img = [info objectForKey:UIImagePickerControllerOriginalImage];
if(self.locationManager.location){
NSDictionary* locationMeta = [self gpsDictionaryForLocation:self.locationManager.location];
[meta setObject:locationMeta forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:img.CGImage metadata:meta completionBlock:^(NSURL* assetUrl, NSError* error){
//.......
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
This code worked fine in iOS7. After I upgraded my device to iOS8, the program was blocked and imagePickerView didn't dismiss.
Is this a bug in iOS8? Anyone can help me?

How to present a semi-transparent (half-cut) viewcontroller in iOS 8

in iOS 7 there is no problem for this method:
_rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[_rootViewController presentViewController:self animated:NO completion:nil];
But in iOS 8 it did nothing.How to solve it? Is it a Bug for iOS 8?
My answer is more simple, below code. This works in iOS8 (XCode6 GM seed).
HogeViewController *vc = [[HogeViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:vc animated:NO completion:nil];
Note this workaround was needed on xcode6_beta7. The lastest xcode6
has the UIModalPresentationOver* styles fixed. So, I'm just assigning them to myModalViewController.modalPresentationStyle and now it works ok.
Finally made it work in iOS 8 after reading the UIPresentationController help and this post
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
MyModalController *myModalController = [[MyModalController alloc] initWithNibName:#"MyModalController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myModalController];
navController.modalPresentationStyle = UIModalPresentationCustom;
navController.transitioningDelegate = myModalController;
[self.navigationController presentViewController:navController animated:YES completion:nil];
You can make the modal view controller inherit from UIViewControllerTransitioningDelegate
#interface MyModalController : UIViewController <UIViewControllerTransitioningDelegate>
and override presentationControllerForPresentedViewController:...
-(UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
if (presented == self) {
return [[TransparentPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
} else {
return nil;
}
}
returning an instance of TransparentPresentationController which inherits from UIPresentationController
#interface TransparentPresentationController : UIPresentationController
and overrides shouldRemovePresentersView
- (BOOL) shouldRemovePresentersView {
return NO;
}

Lock screen orientation for a single controller when there's a UITabBar in IOS 5 & 6

Following are the main poins I have.
I'm new to IOS development
I need to support IOS 5 and IOS 6 in my IOS app
I have a UITabBarController in AppDeligate file as follows.
UIViewController *viewController1 = [[[Grid1ViewController alloc] initWithNibName:#"Grid1ViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[VideoListViewController alloc] initWithNibName:#"VideoListViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[MusicViewController alloc] initWithNibName:#"MusicViewController" bundle:nil] autorelease];
UIViewController *viewController4 = [[[GalleryViewController alloc] initWithNibName:#"GalleryViewController" bundle:nil]autorelease];
UINavigationController *myNav1=[[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *myNav2=[[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *myNav3=[[UINavigationController alloc] initWithRootViewController:viewController3];
UINavigationController *myNav4=[[UINavigationController alloc] initWithRootViewController:viewController4];
UIImage *navBackgroundImg = [UIImage imageNamed:#"aa.png"];
[myNav1.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
[myNav2.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
[myNav3.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
[myNav4.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:myNav1, myNav2, myNav3,myNav4,nil];
4.I want to lock the rotation of every controller which is directly connected to tabBarController( ex - Grid1ViewController). But I need to rotate the some controller which are used in the app. Please refer the following drawing. A,B,C,D and E are controllers.
I tried implementing following method in controllers and AppDeligate file. But didn't work. When rotation are allowed the whole app start to rotate.
(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation{
NSLog(#"5 rotation");
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
// For IOS 6
-(BOOL)shouldAutorotate {
NSLog(#"shouldAutorotate");
return YES;
}
(NSUInteger)supportedInterfaceOrientations {
NSLog(#"6 rotation");
return UIInterfaceOrientationMaskPortrait;
}
How can I achieve this? Please help. Thank you in advance.

UIActivityViewController

I have a problem with the UIActivityViewController on iPad
Here is my Code:
NSString* someText = #"Hi, I am using the official iEveryThing Tech app #iEveryTech";
NSString* Website = [NSURL URLWithString:#"https://itunes.apple.com/us/app/ieverytech/id578148847?l=de&ls=1&mt=8"];
NSArray* dataToShare = #[someText,Website];
Class activityViewController = NSClassFromString(#"UIActivityViewController");
if(activityViewController) {
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];}
}
On iPhone the Mail composer View will disappear after sending the mail but not the Composer on the iPad here is my Composer:
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"error"
message:[NSString stringWithFormat:#"error %#", [error description]]
delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
[self dismissModalViewControllerAnimated:YES];
}
else {
[self dismissModalViewControllerAnimated:YES];
}
}
The activityViewController use a native method for send mail don't need use mailComposeController, like this
NSMutableArray *items = [NSMutableArray new];
[items addObject:#"text for share"];
[items addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:self.imagePath]]];
NSArray *activityItems = [NSArray arrayWithArray:items];
self.activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:[NSArray arrayWithObjects:whatsapp,instagram, nil]];
self.activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint,UIActivityTypeAirDrop,UIActivityTypeCopyToPasteboard];
[self presentViewController:self.activityVC animated:YES completion:nil];
First thing, when using the activityViewController, your class is not the delegate for the mail composer and the code will not be called. This is all handled internally in the activityViewController.
As for your view not being dismissed, implement the complete block call for the activityViewController. In the block be sure to dismiss the view controller.

SIGABRT error during interface change

(IBAction)switchAppointment {
AppointmentController *appt = [[AppointmentController alloc] initWithNibName:nil bundle:nil];
appt.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:appt animated:YES];
[appt release];
}
That is the code that I use to switch from one .xib to another, however on the line that says "self presentModalViewController:appt animated:YES" , I'm getting a SIGABRT error. My app crashes immediately when I try to go into that interface.
FYI too I'm on Xcode 4.2, but it was doing this before I downloaded the beta.
I have also same answer for the code:
nextView *second=[[nextView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
Yours
Miska

Resources