TWTweetComposeVIEwController *tweeter = [[TWTweetComposeVIEwController alloc] init]; [tweeter setinitialText:@"message"]; [tweeter addImage:image]; [self presentModalVIEwController:tweeter animated:YES];
如何在iOS 5中使用Twitter框架获取用户的Twitter个人资料信息?
解决方法 好吧,我们说你想在桌面上显示用户在他们设备上的推特账号.您可能希望在表格单元格中显示头像,在这种情况下,您需要查询Twitter的API.假设您有一个ACAccount对象的NSArray,您可以创建一个字典来存储每个帐户的额外配置文件信息.你的表视图控制器的tableVIEw:cellForRowAtIndexPath:需要这样的代码:
// Assuming that you've dequeued/created a UItableVIEwCell... // Check to see if we have the profile image of this account UIImage *profileImage = nil; NSDictionary *info = [self.twitterProfileInfos objectForKey:account.IDentifIEr]; if (info) profileImage = [info objectForKey:kTwitterProfileImageKey]; if (profileImage) { // You'll probably want some neat code to round the corners of the UIImageVIEw // for the top/bottom cells of a grouped style `UItableVIEw`. cell.imageVIEw.image = profileImage; } else { [self getTwitterProfileImageForAccount:account completion:^ { // Reload this row [self.tableVIEw reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UItableVIEwRowAnimationFade]; }]; }
所有这一切都是从字典词典访问UIImage对象,由帐户标识符键入,然后是静态Nsstring键.如果它没有获得图像对象,则它调用实例方法,传入完成处理程序块,重新加载表行.实例方法看起来有点像这样:
#pragma mark - Twitter- (voID)getTwitterProfileImageForAccount:(ACAccount *)account completion:(voID(^)(voID))completion { // Create the URL NSURL *url = [NSURL URLWithString:@"users/profile_image" relativeToURL:kTwitterapiRootURL]; // Create the parameters NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: account.username,@"screen_name",@"bigger",@"size",nil]; // Create a TWRequest to get the the user's profile image TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodGET]; // Execute the request [request performRequestWithHandler:^(NSData *responseData,NShttpURLResponse *urlResponse,NSError *error) { // Handle any errors properly,not like this! if (!responseData && error) { abort(); } // We should Now have some image data UIImage *profileimg = [UIImage imageWithData:responseData]; // Get or create an info dictionary for this account if one doesn't already exist NSMutableDictionary *info = [self.twitterProfileInfos objectForKey:account.IDentifIEr]; if (!info) { info = [NSMutableDictionary dictionary]; [self.twitterProfileInfos setobject:info forKey:account.IDentifIEr]; } // Set the image in the profile [info setobject:profileimg forKey:kTwitterProfileImageKey]; // Execute our own completion handler if (completion) dispatch_async(dispatch_get_main_queue(),completion); }];}
因此,请确保您正常失败,但是,这将在下载配置文件图像时更新表.在您的完成处理程序中,您可以将它们放在图像缓存中,或者将它们保留在类的生命周期之外.
可以使用相同的过程来访问其他Twitter用户信息,see their docs.
总结以上是内存溢出为你收集整理的objective-c – 如何在iOS 5中使用Twitter框架获取用户的Twitter个人资料信息?全部内容,希望文章能够帮你解决objective-c – 如何在iOS 5中使用Twitter框架获取用户的Twitter个人资料信息?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)