4

您好我正在尝试为 adobe AIR 制作 SMS 原生扩展。我之前没有在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];

它起作用了!!!!非常感谢这个人。你不知道我被困了多少个小时。我很乐意接受您的回答。

4

1 回答 1

6

代替

 [[[[UIApplication sharedApplication] keyWindow] rootViewController] dismissModalViewControllerAnimated:YES];

 [controller dismissModalViewControllerAnimated:YES];

也用于警告

转到SMSComposerHelper.h 并添加以下内容

@interface SMSComposerHelper : UIViewController<MFMessageComposeViewControllerDelegate>{

代替

@interface SMSComposerHelper : UIViewController{
于 2012-06-02T12:16:36.513 回答