您好我正在尝试为adobe AIR制作短信本机扩展程序。 我之前在Objective-c中编码但是一切正常,除了按下发送或取消时SMS窗口不会关闭的事实。下面是代码的主要部分,但问我是否还需要更多信息。谢谢阅读。 为什么xcode告诉我:第二行的“协议中的方法没有实现”?
#import "SMSComposerHelper.h"
@implementation SMSComposerHelper
//Event name
static NSString *event_name = @"SMS_COMPOSER_EVENT";
-(void) sendSMS:(NSString *)toRecipient
messageBody:(NSString *)messageBody
{
FREDispatchStatusEventAsync(context, (uint8_t*)[event_name UTF8String], (uint8_t*)[@"WILL_SHOW_MAIL_COMPOSER" UTF8String]);
MFMessageComposeViewController *smsComposer = [[MFMessageComposeViewController alloc] init];
smsComposer.messageComposeDelegate = self;
//make string into array
NSArray *recipientArray;
recipientArray = [NSArray arrayWithObjects: toRecipient, nil];
smsComposer.body = messageBody;
smsComposer.recipients = recipientArray;
//show sms composer
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:smsComposer animated:YES];
}
// Dismisses the sms composition interface when users tap Cancel or Send.
-(void) smsComposeController: (MFMessageComposeViewController*)controller didFinishWithResult: (MessageComposeResult)result error:(NSError*)error
{
NSString *event_info = @"";
// Notifies users about errors associated with the interface
switch (result)
{
case MessageComposeResultCancelled:
event_info = @"SMS_CANCELED";
break;
case MessageComposeResultSent:
event_info = @"SMS_SENT";
break;
case MessageComposeResultFailed:
event_info = @"SMS_FAILED";
break;
default:
event_info = @"SMS_UNKNOWN";
break;
}
FREDispatchStatusEventAsync(context, (uint8_t*)[event_name UTF8String], (uint8_t*)[event_info UTF8String]);
FREDispatchStatusEventAsync(context, (uint8_t*)[event_name UTF8String], (uint8_t*)[@"WILL_HIDE_SMS_COMPOSER" UTF8String]);
context = nil;
//hide mail composer
[[[[UIApplication sharedApplication] keyWindow] rootViewController] dismissModalViewControllerAnimated:YES];
}
-(void)setContext:(FREContext)ctx {
context = ctx;
}
@end
回应:
奥马尔非常感谢你的回答和快速回答! 首先,我尝试了使用
的解决方案[controller dismissModalViewControllerAnimated:YES];
但这没有做任何事情所以我改回来了。 我的标题已经是:
@interface SMSComposerHelper : NSObject<MFMessageComposeViewControllerDelegate> {
所以我决定专注于修复警告。 警告通过改变来解决:
-(void) smsComposeController: (MFMessageComposeViewController*)controller didFinishWithResult: (MessageComposeResult)result error:(NSError*)error
为:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
我很想知道为什么这有效?你认识奥马尔吗? 所以我解决了警告,但它仍然没有解雇。 所以我再次尝试了你的建议:
[controller dismissModalViewControllerAnimated:YES];
和它一起工作!!!! 非常感谢你。你不知道我被困多少小时。 我很乐意接受你的回答。
答案 0 :(得分:6)
而不是
[[[[UIApplication sharedApplication] keyWindow] rootViewController] dismissModalViewControllerAnimated:YES];
写
[controller dismissModalViewControllerAnimated:YES];
也是警告
转到SMSComposerHelper.h
并添加以下
@interface SMSComposerHelper : UIViewController<MFMessageComposeViewControllerDelegate>{
而不是
@interface SMSComposerHelper : UIViewController{