如何显示VC用于iOS应用程序的顺序发送电子邮件,短信,推文和Facebook状态

时间:2014-01-05 12:35:26

标签: ios objective-c facebook twitter ios7

我正在尝试通过短信,EMAIL将iPhone的GPSLocation坐标发送到收件人列表,并将其发布到Facebook并在Twitter上发送推文,点击一下按钮。(我收到了收件人邮件和电话号码从其他标签视图列表)

但无论我尝试过什么,我都无法按顺序发送邮件,消息,推文和Facebook发送视图。

请帮助我,我们将不胜感激。

我正在使用 Xcode 5 iOS 7 进行开发。

我收到了这些消息(我猜现在null是因为模拟器无法模拟发送短信,对于其他消息我不知道其背后的原因)

2014-01-05 14:26:47.232 iPanic [4760:70b]尝试呈现(null)等待延迟呈现完成

2014-01-05 14:26:47.236 iPanic [4760:70b]尝试出现等待延迟完成的提示

我的选项卡控制器FirstViewController:MRHFirstViewController.m如下:

#import "MRHFirstViewController.h"

@interface MRHFirstViewController ()

@end

@implementation MRHFirstViewController


@synthesize emergencyContacts;


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewWillAppear:(BOOL)animated
{
emergencyContacts = [[NSUserDefaults standardUserDefaults]
                     objectForKey:@"recipients"];
}

- (void)didReceiveMemoryWarning
 {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
[locationManager stopUpdatingLocation];
CLLocation *newLocation = [locations lastObject];
NSString *latitude= [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.latitude];
NSString *longitude=[[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.longitude];
NSString *SILlatitude= [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
NSString *SILlongitude=[[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];    

NSString *message =[NSString
                    stringWithFormat:@"Hi,I need help.MyGPSlocation: %@, %@.Please Help Me Immediately. http://maps.google.com/maps?q=%@,%@ "
                    ,latitude,longitude,SILlatitude,SILlongitude];

 //Send Mail START
mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:[[NSUserDefaults standardUserDefaults] objectForKey:@"emailList"]];
[mailComposer setSubject:@"Help!!!"];
[mailComposer setMessageBody:message isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
 //Send Mail END



//SEND SMS START
messageComposer = [[MFMessageComposeViewController alloc] init];
[messageComposer setRecipients:[[NSUserDefaults standardUserDefaults] objectForKey:@"phoneList"]];
[messageComposer setBody:message];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
//SEND SMS END

//tweet and FB START
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

[composeController setInitialText:message];
//[composeController addImage:[UIImage imageNamed:@"image.png"]];
//[composeController addURL: [NSURL URLWithString:@"http://www.apple.com"]];

[self presentViewController:composeController
                   animated:YES completion:nil];

SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) //check if Facebook Account is linked
    {
        mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller
        mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //Tell him with what social plattform to use it, e.g. facebook or twitter
        [mySLComposerSheet setInitialText:message]; //the message you want to post
        //[mySLComposerSheet addImage:yourimage]; //an image you could post
        //for more instance methodes, go here:https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40012205
        [self presentViewController:mySLComposerSheet animated:YES completion:nil];

        NSLog(@"Account is linked!!!");
    }else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:@"lan" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        NSLog(@"Account is not linked hafiz");
    }

};
composeController.completionHandler =myBlock;
    //tweet and FB END

}

- (IBAction)doPanic:(id)sender {

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];

}

下面的MRHFirstViewController.h:

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MessageUI/MessageUI.h>
#import <Social/Social.h>

@interface MRHFirstViewController : UIViewController<CLLocationManagerDelegate,MFMailComposeViewControllerDelegate,MFMessageComposeViewControllerDelegate>
{
CLLocationManager *locationManager;
MFMailComposeViewController *mailComposer;
MFMessageComposeViewController *messageComposer;
SLComposeViewController *mySLComposerSheet;
}

@property (strong,nonatomic) NSMutableArray *emergencyContacts;
@property NSString *SILlat;
@property NSString *SILlon;
@property (strong, nonatomic) IBOutlet UILabel *silLabel;
- (IBAction)doPanic:(id)sender;
@end

1 个答案:

答案 0 :(得分:0)

您应该在完成委托回调中显示新的视图控制器。也就是说,例如,当您的推特代表告诉您已发送推文时,呈现邮件视图控制器,当它的代表告诉您完成时,呈现Facebook视图控制器,等等(按顺序)你想要的。)