iOS MailComposer을 열 때 rhodes 기본 확장 프로그램 확장을 쓰려고했습니다. 열기. 이제 코드는 "작동"하지만 MFMailComposeViewController가 표시되지와 엑스 코드 경고 보여줍니다Ios MFMailComposeViewController not displa
Attempt to present <MFMailComposeViewController: 0x12b60840> on <Iosmailto: 0xc1898d0> whose view is not in the window hierarchy!
내가 UIViewControllers 계층 구조에 있어야 읽을 수 있지만 내가 로즈 루비 코드 또는 명확한-C의 확장에서이를 제공 할 수 없습니다 싸개. 지금 내가 [UIApplication sharedApplication] .keyWindow.rootViewController에서 MFMailComposeController 내 의 UIViewController를 제공하기 위해 노력하고있어하지만 메일 작곡가는 아직 보여주지. iosmailto.h에서
인터페이스 : iosmailto.m에서
@interface Iosmailto : UIViewController<MFMailComposeViewControllerDelegate>
{
}
@property(nonatomic, assign) id delegate;
//-(IBAction)send_mail:(id)sender;
@end
구현 :
@implementation Iosmailto
- (void)viewDidLoad {
[super viewDidLoad];
[self send_mail];
}
- (void)send_mail {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:[NSString stringWithUTF8String:subj]];
NSArray *recipients_array = [NSArray arrayWithObject:[NSString stringWithUTF8String:recipients]];
[composer setToRecipients:recipients_array];
NSString *composerBody = [NSString stringWithUTF8String:message];
[composer setMessageBody:composerBody isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
} else {
NSLog(@"Device is unable to send email in its current state.");
}
}
/* some unnecessary for this question methods */
@end
그리고 데스 호출 iosmailto.m 이잖아 정의 C 함수 :
// find root vc
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
// find topmost vc
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
iosmailer = [[Iosmailto alloc] init];
iosmailer.delegate = topController;
[topController presentViewController:iosmailer animated:YES completion:nil];
이 앱은 AppStore 용 앱이 아닙니다. 필요할 경우 해킹을 환영합니다. Iosmailto에 대한
업데이트 초기화 :
- (id)init
{
self = [super initWithNibName:nil bundle:nil];
return self;
}
업데이트 2 (UIViewController에 래퍼 제외)이 코드의 짧은 버전은 내 출발점이었다. 그것도 효과가 없습니다.
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = (id<MFMailComposeViewControllerDelegate>)topController ;
[composer setSubject:[NSString stringWithUTF8String:subj]];
NSArray *recipients_array = [NSArray arrayWithObject:[NSString stringWithUTF8String:recipients]];
[composer setToRecipients:recipients_array];
NSString *composerBody = [NSString stringWithUTF8String:message];
[composer setMessageBody:composerBody isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[topController presentModalViewController:composer animated:YES];
[composer release];
} else {
}
당신의 init 메소드 Iosmailto에 대한 어떤 모습의 현재이란? initWithNib : (사용자의 서브 클래스에서 상속 된 UIViewController에 정의 됨) 또는 사용자 지정 init 메서드가 [super initWithNib :]를 호출하는지 확인해야합니다. – Idles
init을 사용하여 업데이트 함 – rootatdarkstar
래퍼가없는 코드에 대한 업데이트 수행 – rootatdarkstar