xCode - 发送短信在应用程序

时间:2015-06-17 17:37:17

标签: ios objective-c xcode sms

我想从我的应用程序发送短信。我用于以下代码:

·H

#import <UIKit/UIKit.h>    
#import <MessageUI/MessageUI.h>

    @interface askFriendsViewController : UIViewController <MFMailComposeViewControllerDelegate>

-(IBAction)sms:(id)sender;

的.m

-(IBAction)sms:(id)sender{

    MFMessageComposeViewController *textComposer = [[MFMessageComposeViewController alloc]init];
    [textComposer setMessageComposeDelegate:self];

    if ([MFMessageComposeViewController canSendText]) {
        [textComposer setBody:@"Text"];
        [self presentViewController:textComposer animated:YES completion:nil];
        [[UIApplication sharedApplication] setStatusBarHidden:YES];


        [textComposer preferredInterfaceOrientationForPresentation];
    }
    else {
        NSLog(@"SMS not working.");
    }


}

对于.m文件中的第三行,我收到错误:

  

发送&#39; askFriendsViewController * const __strong&#39;参数   不兼容的类型&#39; id&#39;

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您声明您的类符合MFMailComposeViewControllerDelegate协议,而不是头文件中的MFMessageComposeViewControllerDelegate。将其更改为MFMessageComposeViewControllerDelegate并实现它 messageComposeViewController:didFinishWithResult:method。