이것은 phonegap에 대한 내 SMS 플러그인의 일부 코드입니다. 콜백이 올바르게 작동하도록하려고합니다. https://github.com/aharris88/phonegap-sms-plugin/issues/11Phonegap iOS 플러그인 - didFinishWithResult에서 콜백에 액세스하는 방법
다음 코드는 제가 작업하고 있습니다. 당신은 내가 이런 송신 방법의 시작 부분에 콜백 함수를 얻을 볼 수 있습니다
NSString* callback = command.callbackId;
그럼 내가 MFMessageComposeViewController 제시하고 나는 그것이 완료 때 콜백을 호출해야합니다. 그래서 messageComposeViewController : didFinishWithResult :를 사용하고 있습니다. 그러나 호출해야하는 콜백 함수에 어떻게 액세스 할 수 있습니까?
#import "Sms.h"
#import <Cordova/NSArray+Comparisons.h>
@implementation Sms
- (CDVPlugin *)initWithWebView:(UIWebView *)theWebView {
self = (Sms *)[super initWithWebView:theWebView];
return self;
}
- (void)send:(CDVInvokedUrlCommand*)command {
NSString* callback = command.callbackId;
if(![MFMessageComposeViewController canSendText]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notice"
message:@"SMS Text not available."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
return;
}
MFMessageComposeViewController* composeViewController = [[MFMessageComposeViewController alloc] init];
composeViewController.messageComposeDelegate = self;
NSString* body = [command.arguments objectAtIndex:1];
if (body != nil) {
[composeViewController setBody:body];
}
NSArray* recipients = [command.arguments objectAtIndex:0];
if (recipients != nil) {
[composeViewController setRecipients:recipients];
}
[self.viewController presentViewController:composeViewController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
#pragma mark - MFMessageComposeViewControllerDelegate Implementation
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
int webviewResult = 0;
CDVPluginResult* pluginResult = nil;
switch(result) {
case MessageComposeResultCancelled:
webviewResult = 0;
break;
case MessageComposeResultSent:
webviewResult = 1;
break;
case MessageComposeResultFailed:
webviewResult = 2;
break;
default:
webviewResult = 3;
break;
}
[self.viewController dismissViewControllerAnimated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
if (webviewResult == 1) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Arg was null"];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:callback];
}
@end
대리자 메서드에 중단 점을 넣었습니까? 메시지보기 컨트롤러가 완료되면 호출됩니까? – Joshua
예, 자동으로 호출됩니다. 변수 NSString * 콜백에 액세스 할 수 없습니다. – aharris88