如何通过邮件,推特和Facebook从当前的应用程序分享或发布? [英] How to share or post by mail, twitter and facebook from the current application?

查看:199
本文介绍了如何通过邮件,推特和Facebook从当前的应用程序分享或发布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施一个应用程序,我必须在Facebook上分享这些应用程序, Twitter 以及通过邮件。由于我的应用程序不是游戏,我只想提供应用程序图标,应用程序名称,该应用程序的iTunes链接以及应用程序的小描述。我已经实现了允许我发送附件邮件的代码。这有用吗?我该怎么做?

I am implementing an application from which I have to share that applications on Facebook, Twitter as well as by mail. As my application is not a game, I just want to put an application icon, application name, iTunes link of that application and a small description of the application. I have implemented code which allow me to send a mail with attachment. Is that useful here? How can I do this?

推荐答案

1。对于Facebook。

FBGraph 是一种在应用程序中使用 Facebook API 的更好方法。

FBGraph is a much better way to use the Facebook API in your application.

下载 FBGraph API 文档文件夹,然后将其添加到您的文件夹中。阅读 Facebook开发者网站上的说明。

Download the FBGraph API documents folder and then add it to in your folder. Read the instructions on the Facebook developer site.

这是示例代码,如果您对此有任何疑问,请与我们联系。

This is the sample code and let me know if you have any query about it.

2。对于电子邮件

在项目中添加 MessageUI.framework 。在 ViewController.h 文件中导入头文件:

Add MessageUI.framework in your project. Import the header file in your ViewController.h file:

 #import <MessageUI/MFMailComposeViewController.h>

设置代理人:

UIViewController<MFMailComposeViewControllerDelegate>

之后,打开你的邮件编辑器:

And after that, open your mail composer like this:

-(void)yourEmailbuttonClick:(id)sender
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Hello!! your subject here"];

    // Set up recipients
    UIImage *image = [UIImage imageNamed:@"anyImage.png"];
    NSData *myData = UIImageJPEGRepresentation(image, 1.0);
    [picker addAttachmentData:myData mimeType:@"image/jpg" fileName:@"image"];
    [self presentModalViewController:picker animated:YES];
}


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            //        message.text = @"Result: canceled";
            break;
        case MFMailComposeResultSaved:
            //        message.text = @"Result: saved";
            break;
        case MFMailComposeResultSent:
            //            message.text = @"Result: sent";
            break;
        case MFMailComposeResultFailed:
            //            message.text = @"Result: failed";
            break;
        default:
            //            message.text = @"Result: not sent";
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}

3。对于Twitter

在项目中添加 Twitter.framework 。在 ViewController.h 文件中导入头文件并导入:

Add Twitter.framework in your project. Import the header file in your ViewController.h file and import:

#import <Twitter/Twitter.h>

现在按这样调用Twitter作曲家视图:

Now call the Twitter composer view like this:

-(void)yourTwitterbuttonClick:(id)sender
{
    if([TWTweetComposeViewController canSendTweet])
    {
        UIImage *image = [UIImage imageNamed:@"anyImage.png"];
        TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
        // Set initial text
        [tweetViewController setInitialText:@"your text here"];

        if (image)
        {
            [tweetViewController addImage: image];
        }

        tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result)
        {
            if(result == TWTweetComposeViewControllerResultDone)
            {
                // The user finished composing a tweet
                alert.title=@"Status";
                alert.message=@"Tweet sent";
                [alert show];
            }
            else
                if(result == TWTweetComposeViewControllerResultCancelled)
                {
                    // The user cancelled composing a tweet
                    alert.title = @"Status";
                    alert.message = @"Tweet cancelled";
                    [alert show];
                }
            [self dismissViewControllerAnimated:YES completion:nil];
        };
        [self presentViewController:tweetViewController animated:YES completion:nil];
    }
}

这篇关于如何通过邮件,推特和Facebook从当前的应用程序分享或发布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆