MFMailComposeViewController in iOS 8

2019-08-06 10:04发布

问题:

First, my app worked fine on iOS 7, since iOS 8 i can't send in-app email thru "MFMailComposeViewController". Message window comes up, only shows subject of the mail and closes within seconds. I found this thread here which describes my problem and now tried to implement the answer from "Joe Blow" https://stackoverflow.com/a/25864182/4061869

But im getting some errors, some sematic and parse issues.

Worst thing according to this part of the workaround:

Of course have this in your Prefix file

#define APP ((AppDelegate *)[[UIApplication sharedApplication] delegate])
// it's worth noting that is the delegate, not the "application"

Leads to this error:

Use of undeclared identifier 'AppDelegate'

Anyone knows where the problem can be? I tried different wordings on 'AppDelegate' according to my filename of the appdelegat.h/.m but nothing helps.

回答1:

You can define the app delegate in whichever ViewController you are working in, by using:

AppNameAppDelegate *APP = [[UIApplication sharedApplication]delegate];

To state the obvious, by AppName I mean the name of your application. Make sure to import the AppDelegate.h into your .m file too.

#import "AppNameAppDelegate.h"

For the record, I am also having the same issue with MFMailComposeViewController,and I have tried the method suggested in the post you linked (creating a global mail composer), but it still won't work for me using the iOS 8 simulator. Apparently it works on a physical device running iOS 8, but I personally cannot confirm that just yet.