gpt4 book ai didi

iphone - SMS 窗口不会关闭 objective-C

转载 作者:可可西里 更新时间:2023-11-01 05:31:30 24 4
gpt4 key购买 nike

您好,我正在尝试为 adobe AIR 制作 SMS 原生扩展。我之前没有用 objective-c 编码,但除了按下发送或取消时 SMS 窗口不会关闭之外,一切正常。下面是代码的主要部分,但如果您需要更多信息,请问我。谢谢阅读。还有为什么 xcode 告诉我:第二行的“协议(protocol)中的方法未实现”?

#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

回应:

Omar 非常感谢您的回答,而且回答得这么快!首先,我尝试了您使用

的解决方案
[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];

成功了!!!!非常感谢,伙计。你不知道我被困了多少个小时。我很乐意接受你的回答。

最佳答案

代替

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

 [controller dismissModalViewControllerAnimated:YES];

也为警告

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

@interface SMSComposerHelper : UIViewController<MFMessageComposeViewControllerDelegate>{

代替

@interface SMSComposerHelper : UIViewController{

关于iphone - SMS 窗口不会关闭 objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10862216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com