人人开放平台

前端之家收集整理的这篇文章主要介绍了人人开放平台前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

http://wiki.dev.renren.com/wiki/IOS%E6%8E%A5%E5%85%A5%E6%95%99%E7%A8%8B

JSON,FMDB和Renren三个文件

在Prefix文件中引入ROConnect.h头文件

add一个sqlite3.0

接下来将自己的APP ID和API Key添加到renren.h文件

页面控制类RenrenSDKDemoViewController,需要实现RenrenDelegate的代理方法,来处理登录成功和登录失败的情况<RenrenDelegate>

//登陆部分

- (IBAction)ToLogin:(id)sender {

if(![[RenrensharedRenren]isSessionValid]){//登录的情况,进行授权登录

[[RenrensharedRenren]authorizationWithPermisson:nilandDelegate:self];

} else {//登录的情况,退出登录

[[RenrensharedRenren]logout:self];

}

}

/**

* 授权登录成功时被调用,第三方开发者实现这个方法

* @param renren 传回代理授权登录接口请求的Renren类型对象。

*/

- (void)renrenDidLogin:(Renren *)renren

{


}


/**

* 用户登出成功后被调用 第三方开发者实现这个方法

* @param renren 传回代理登出接口请求的Renren类型对象。

*/

- (void)renrenDidlogout:(Renren *)renren

{


}


/**

* 授权登录失败时被调用,第三方开发者实现这个方法

* @param renren 传回代理授权登录接口请求的Renren类型对象。

*/

- (void)renren:(Renren *)renren loginFailWithError:(ROError*)error

{

UIAlertView *alertView =[[[UIAlertViewalloc]initWithTitle:@"错误提示" message:@"授权失败" delegate:nilcancelButtonTitle:@"确定" otherButtonTitles:nil] autorelease];

[alertView show];

}


//下载好友并显示再tv中

//

// FriViewController.m

// RenrenFriends

//

// Created by imac53 on 12-7-22.

// Copyright (c) 2012 __MyCompanyName__. All rights reserved.

//


#import "FriViewController.h"


@interface FriViewController ()


@end


@implementation FriViewController

@synthesize tv_friends;

@synthesize friendsList;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

// Custom initialization

}

return self;

}


- (void)viewDidLoad

{

[superviewDidLoad];

// Do any additional setup after loading the view from its nib.

if([[RenrensharedRenren]isSessionValid]){//登录状态,设置requestParam,设置请求参数:好友列表第1,500,name字段的数据.

ROGetFriendsInfoRequestParam *requestParam = [[[ROGetFriendsInfoRequestParamalloc]init]autorelease];

requestParam.page = @"1";

requestParam.count = @"500";

requestParam.fields = @"name";

[[RenrensharedRenren]getFriendsInfo:requestParamandDelegate:self];

} else {//登录状态提示用户"您还没有授权"

UIAlertView *alertView =[[[UIAlertViewalloc]initWithTitle:@"提示"message:@"您还没有授权" delegate:nilcancelButtonTitle:@"确定" otherButtonTitles:nil] autorelease];

[alertView show];

}

}


- (void)viewDidUnload

{

[selfsetTv_friends:nil];

[superviewDidUnload];

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

return (interfaceOrientation == UIInterfaceOrientationPortrait);

}


- (void)dealloc {

[tv_friends release];

[super dealloc];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return [self.friendsListcount];

}

/**

* 接口请求成功,第三方开发者实现这个方法

* @param renren 传回代理服务器接口请求的Renren类型对象。

* @param response 传回接口请求的响应。

*/

- (void)renren:(Renren *)renren requestDidReturnResponse:(ROResponse*)response

{

//创建好友数组.

self.friendsList = [[[NSMutableArrayalloc]init] autorelease];

//取得请求结果.

NSMutableArray *friendsArray = (NSMutableArray *)response.rootObject;

//将请求结果对象中的name信息放到数组中.

for (ROUserResponseItem *friendin friendsArray) {

[self.friendsListaddObject:friend.name];

}

//Table View重新加载数据.

[self.tv_friendsreloadData];

}


/**

* 接口请求失败,第三方开发者实现这个方法

* @param renren 传回代理服务器接口请求的Renren类型对象。

* @param response 传回接口请求的错误对象。

*/

- (void)renren:(Renren *)renren requestFailWithError:(ROError*)error

{

UIAlertView *alertView =[[[UIAlertViewalloc]initWithTitle:@"错误提示" message:@"API请求错误" delegate:nilcancelButtonTitle:@"确定" otherButtonTitles:nil] autorelease];

[alertView show];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

if (indexPath.row <self.friendsList.count) {

UITableViewCell *cell = (UITableViewCell*)[tableViewdequeueReusableCellWithIdentifier:@"friendsListCell"];

if (cell == nil) {

cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"friendsListCell"]autorelease];

}

cell.textLabel.text = (NSString *)[self.friendsListobjectAtIndex:indexPath.row];

return cell;

}

return nil;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 44;

}

@end



//delegate函数中不同请求的判断

if ([request.requestParamObject.methodisEqualToString:@"users.getLoggedInUser"])

if([response.param.methodisEqualToString:@"friends.getFriends"])


//取得当前用户的id

[[RenrensharedRenren] getLoggedInUserId];

NSUserDefaults *defaults=[NSUserDefaultsstandardUserDefaults];

NSString *uid=[defaults objectForKey:@"session_UserId"];


//获取用户信息

//设置参数

userParam.userIDs=uid;

userParam.fields=@"name";

//发送请求

[[RenrensharedRenren] getUsersInfo:userParamandDelegate:self];

- (void)renren:(Renren *)renren requestDidReturnResponse:(ROResponse*)response

if([response.param.methodisEqualToString:@"users.getInfo"])

{

//取得请求结果.

NSMutableArray *userArray = (NSMutableArray *)response.rootObject;

//将请求结果对象中的name信息放到数组中.

for (ROUserResponseItem *userin userArray) {

[self.label_usernamesetText:user.name];


}


}

}


//发布状态

- (IBAction)ToLogin:(id)sender {

if(![[Renren sharedRenren] isSessionValid]){//登录的情况,进行授权登录

//授权时需要多加一个参数permisson

NSArray *permisson=[[NSArray alloc] initWithObjects:@"status_update",nil];

[[Renren sharedRenren] authorizationWithPermisson:permisson andDelegate:self];

} else {//登录的情况,退出登录

[[Renren sharedRenren] logout:self];

}

}

- (IBAction)ToPublic:(id)sender {

//要发布的内容

NSString *meg=tf_public.text;

//配置参数对象

NSMutableDictionary *param=[[NSMutableDictionary alloc] init];

[param setValue:meg forKey:@"status"];

[param setValue:@"status.set" forKey:@"method"];

//调用requestWithParams方法并传入param

[[Renren sharedRenren] requestWithParams:param andDelegate:self];

}

原文链接:https://www.f2er.com/sqlite/201917.html

猜你在找的Sqlite相关文章