Social Networking Programming API
Social networking programming primarily uses the social framework provided by iOS, and currently the social framework consists of two main classes:
- Slcomposeviewcontroller
- A view controller that provides social information (such as Weibo information), an iOS system that provides a UI, or a small pop-up box that is written to share content.
- Slrequest encapsulates HTTP requests, provides the same interface to request social networking services, the ability to communicate directly with social networking services, and no UI needs to write its own design.
- In addition to the social framework, it is possible to use UIACTIVITYVIEWCONTROLELR and Acaccount.uiactivityviewcontroller as well as IOS6 's new content, which provides a shared list view controller. While Acaccount is a class in the accounts framework, the Acaccount object encapsulates the user account information stored in the account database and uses the Acaccount object to provide user account information when accessing social network services using Slrequest.
IOS6 Share list------Uiactivityviewcontroller
A share list view is provided after IOS6, which is managed through Uiactivityviewcontroller. The main purpose of Apple's design is to replace the Share Action menu (Actionsheet) and share the Action menu for the purpose of sharing the Action menu.
Built-in Activity list item
There are 9 active list items built in, and they are defined by the following 9 constants:
- Uiactivitytypeposttofacebook,facebook activity list item;
- Uiactivitytypeposttotwitter,twitter activity list item;
- Uiactivitytypeposttoweibo, Sina Weibo activity list item;
- The list item of the imessage application activity in Uiactivitytypemessage,ios;
- Uiactivitytypemail, send mail activity list item;
- Uiactivitytypeprint, share print activity list items;
- Uiactivitytypecopytopasteboard, copy to clipboard activity list item;
- Uiactivitytypeassigntocontact, access the Contact Activity list item;
- Uiactivitytypesavetocameraroll, access the album Activity list item on the device;
Customizing Activity list Items
Sometimes, depending on the shared content, you need to customize the active list item. For example a video that needs to be shared to Youku. The following describes the custom Activity list item.
- -(NSString *) Activitytype, specify a service type identity for the custom Activity list item
- -(NSString *) Activitytitle, specifying the name that appears in the list
- -(UIImage *) Activityimage, specifying icons displayed in the list
- -(BOOL) Canperformwithactivityitems: (Nsarray *) Activityitems, specifies whether certain data items in the active list can be executed, returns YES can be executed, returns no, cannot be executed.
- -(void) Preparewithactivityitems: (Nsarray *) Activityitems, Preprocessing data items in the list of activities to be executed;
- -(Uiviewcontroller *) Activityviewcontroller, Executes the list of activities, and if non-nil is returned, the modal view pops up and the activitydidfinish is called at the end;
- -(void) performactivity, executes the list of activities, if the Activityviewcontroller method does not provide a view, the method is called. Call Activitydidfinish at the end;
- -(void) Activitydidfinish: (BOOL) completed, Which method must be called when execution is complete;
The size of the picture used to customize the view
- Book.png Ordinary iphone device, resolution not less than 43*43
- [email protected] , Retina display iphone device, resolution not less than 86*86
- Book~ipad.png, ordinary ipad device, resolution not less than 55*55
- [Email protected]~ipad.png, Retina display ipad device, resolution not less than 110*110
Code Show:
Customizing the Activity List
-(Ibaction) ShareAction: (Uibarbuttonitem *) Sender { Nsurl *urltbshare = [nsurl urlwithstring:@ "/http/ Www.notepadapi.sinaapp.com "]; Nsarray *activityitems = @[urltbshare]; Bookactivity *bookactivity = [bookactivity new]; Nsarray *applicationactivities = @[bookactivity]; Uiactivityviewcontroller *ACTIVITYVC = [[Uiactivityviewcontroller alloc] Initwithactivityitems:activityitems Applicationactivities:applicationactivities]; [Self PRESENTVIEWCONTROLLER:ACTIVITYVC animated:yes completion:nil];}
BookActivity.h
#import <UIKit/UIKit.h> @interface bookactivity:uiactivity@property (nonatomic,strong) Nsurl *url; @end
Bookactivity.m
#import "BookActivity.h" @implementation bookactivity/* Specify a service type identity for the custom Activity list item */-(NSString *) Activitytype { return Nsstringfromclass ([self class]);} -(NSString *) Activitytitle { return @ "Activitytitle";} /**/-(UIImage *) activityimage { return [UIImage imagenamed:@ "image"];} -(BOOL) Canperformwithactivityitems: (Nsarray *) Activityitems {for (id activityitem in activityitems) { if ([ Activityitem Iskindofclass:[nsurl class]] { if ([[[UIApplication sharedapplication] Canopenurl:activityitem]) { return YES;}} } return NO;} -(void) Preparewithactivityitems: (Nsarray *) Activityitems {for (id activityitem in activityitems) { if ([ Activityitem Iskindofclass:[nsurl class]) { _url = Activityitem;}}} -(void) performactivity { BOOL completed = [[UIApplication sharedapplication] openurl:_url]; [Self activitydidfinish:completed];} @end
Compose the View controller---Slcomposeviewcontroller
It's presented in a modal view of the iphone, and the ipad requires PopOver view rendering
If sending Weibo information is not like a pop-up share list, then choose, but in the app directly into the place to write comments (iOS system provides UI screen). The Slcomposeviewcontroller class can help us achieve this, SLCOMPOSEVIEWCONTROLELR not only write Weibo, but also write tweets and Facebook.
Sending such social network information typically contains 3 of the information---initial text, images, and hyperlinks, so the Slcomposeviewcontroller class designs 3 relative methods:
- -(BOOL) Setinitialtext: (NSString *) text, setting the initial text content
- -(BOOL) AddImage: (UIImage *) iamge, add image
- -(BOOL) Addurl: (nsurl *) URL, add hyperlink information
Code Show
-(Ibaction) Zhuanxieaction: (Uibarbuttonitem *) Sender {Slcomposeviewcontroller *COMPOSEVIEWCONTROLELR = [ Slcomposeviewcontroller Composeviewcontrollerforservicetype:slservicetypefacebook]; if ([Slcomposeviewcontroller Isavailableforservicetype:slservicetypefacebook]) {slcomposeviewcontrollercompletion Handler __block Completionhandler = ^ (slcomposeviewcontrollerresult result) {[COMPOSEVIEWCONTROLELR Dismissviewcon Trolleranimated:yes Completion:nil]; Switch (Result) {case Slcomposeviewcontrollerresultcancelled:nslog (@ "Canceled ..."); Break Case Slcomposeviewcontrollerresultdone:nslog (@ "Posted ..."); Break Default:break; } }; [COMPOSEVIEWCONTROLELR addimage:[uiimage imagenamed:@ "image"]; [COMPOSEVIEWCONTROLELR setinitialtext:@ "Share text"]; [COMPOSEVIEWCONTROLELR Addurl:[nsurl Urlwithstring:@ "http://www.baidu.com"]; [COMPOSEVIEWCONTROLELR Setcompletionhandler:completionhandler]; [Self PRESENTVIEWCONTROLLER:COMPOSEVIEWCONTROLELR animated:yes completion:nil]; }}
Social Networking Programming API's iOS system comes with share