9.42. IOS-Twitter and Facebook

发布时间 :2025-10-25 12:23:56 UTC      

9.42.1. Brief introduction

Twitter has been integrated into iOS5.0, while Facebook has been integrated into iOS 6.0. This tutorial focuses on how to deploy Twitter and Facebook in iOS5.0 and iOS6.0 using classes provided by Apple.

9.42.2. Instance step

  1. Create a simple View based application

two。 Select the project file, then select targets, and then add Social.framework and Accounts.framework to the choose frameworks (select frame)

3. 添加两个名为facebookPost 和 twitterPost的按钮,并为他们创建 ibActions。

  1. Update the ViewController.h as follows

#import <Social/Social.h>
#import <Accounts/Accounts.h>
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

-(IBAction)twitterPost:(id)sender;
-(IBAction)facebookPost:(id)sender;

@end
  1. Update ViewController.m, as shown below

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

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

-(IBAction)facebookPost:(id)sender{

   SLComposeViewController *controller = [SLComposeViewController
   composeViewControllerForServiceType:SLServiceTypeFacebook];
   SLComposeViewControllerCompletionHandler myBlock =
   ^(SLComposeViewControllerResult result){
          if (result == SLComposeViewControllerResultCancelled)
          {
            NSLog(@"Cancelled");
          }
          else
          {
            NSLog(@"Done");
          }
          [controller dismissViewControllerAnimated:YES completion:nil];
        };
   controller.completionHandler =myBlock;
   //Adding the Text to the facebook post value from iOS
   [controller setInitialText:@"My test post"];
   //Adding the URL to the facebook post value from iOS
   [controller addURL:[NSURL URLWithString:@"http://www.test.com"]];
   //Adding the Text to the facebook post value from iOS
   [self presentViewController:controller animated:YES completion:nil];
}

-(IBAction)twitterPost:(id)sender{
    SLComposeViewController *tweetSheet = [SLComposeViewController
    composeViewControllerForServiceType:SLServiceTypeTwitter];
    [tweetSheet setInitialText:@"My test tweet"];
    [self presentModalViewController:tweetSheet animated:YES];
}

@end

9.42.3. Output

When we run the application and click facebookPost, we will get the following output

FBTwit_Output1

When we click twitterPost, we get the following output

FBTwit_Output2

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.