IOS代理在本机扩展中

时间:2016-01-26 16:45:57

标签: ios objective-c haxe openfl

我尝试将MFMessageComposeViewController集成到自定义本机扩展中。 除了一件事之外,控制器工作得很好......当我点击取消按钮或发送消息时,我无法取消或取消控制器。 代表有一个问题,我不知道如何解决。

标题

@interface platools : UIViewController <MFMessageComposeViewControllerDelegate>

函数调用

bool shareIMessage(const char *url)
{
    if(![MFMessageComposeViewController canSendText])
    {
        UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [warningAlert show];
        return false;
    }

    NSLog(@"shareIMessage");
    NSString *ImageStrUrl = [NSString stringWithFormat:@"%s",url];
    NSLog(@"%@",ImageStrUrl);
    NSURL *ImageURL = [NSURL URLWithString:ImageStrUrl];
    NSData *imageData = [NSData dataWithContentsOfURL:ImageURL];

    UIViewController *root = [[[UIApplication sharedApplication] keyWindow] rootViewController];

    MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
    messageController.messageComposeDelegate = (id<MFMessageComposeViewControllerDelegate>)[[UIApplication sharedApplication]delegate];

    if ([MFMessageComposeViewController canSendAttachments])
    {
        NSLog(@"Attachments Can Be Sent.");
        BOOL didAttachImage = [messageController addAttachmentData:imageData typeIdentifier:@"public.data" filename:@"image.gif"];

        if (didAttachImage)
        {
            NSLog(@"Image Attached.");

        }
        else
        {
            NSLog(@"Image Could Not Be Attached.");
        }
    }

    [root presentViewController:messageController animated:YES completion:nil];
    return true;
}

功能代理

void messageComposeViewController(MFMessageComposeViewController* controller)
{
    NSLog(@"messageComposeViewController");
    UIViewController *root = [[[UIApplication sharedApplication] keyWindow] rootViewController];
    // Close the Mail Interface
    [root dismissViewControllerAnimated:YES completion:nil];
}
void didFinishWithResult(MessageComposeResult result)
{
    NSLog(@"didFinishWithResult");

}

完整代码:http://pastebin.com/tuJY0mwv(目标函数是sendIMessage)

0 个答案:

没有答案