【发布时间】:2014-01-09 01:18:21
【问题描述】:
我有两个 SL 请求:
- (void)viewDidLoad
{
#pragma alertView
// load an alert to indicate that the app is loading from the internet
loadingAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"Updating" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
#pragma activity indicator
// create an activity indicator and dump it into the alert
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loadingAlert addSubview:progress];
[progress startAnimating];
// display alert
[loadingAlert show];
// load the nib customized cell
UINib* twitterCellNib = [UINib nibWithNibName:@"TwitterViewCell" bundle:nil];
if (twitterCellNib != nil) {
[tweetTableView registerNib:twitterCellNib forCellReuseIdentifier:@"TwitterCell"];
}
// all tweeter operations need to go through this filter
// create an account-store object
ACAccountStore *accountStore = [[ACAccountStore alloc]init];
if (accountStore != nil) {
// create an account type
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
if (accountType != nil) {
// request access (on device pop-up) on sim. permanent
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted) {
// code that needs to exect if access is granted here
// get a list with all the accounts in the device/sim
NSArray *twitterAccount = [accountStore accountsWithAccountType:accountType];
if (twitterAccount != nil) {
ACAccount *workingAccount = [twitterAccount objectAtIndex:0];
if (workingAccount != nil) {
// username of the account
NSString *userName = workingAccount.username;
// create SL request for user profile info ______________________________
NSMutableString* userProfileRequest = [[NSMutableString alloc] initWithString:@"https://api.twitter.com/1.1/users/show.json?screen_name="];
[userProfileRequest appendString:userName];
// create an SL request for user information
SLRequest *requestUserInfo = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:userProfileRequest] parameters:nil];
if (requestUserInfo != nil) {
[requestUserInfo setAccount:workingAccount];
// perform request
[requestUserInfo performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
// check response from the server
NSInteger codeServer = [urlResponse statusCode];
if (codeServer == 200) {
// catch the user info from the api
userProfileArray = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
if (userProfileArray != nil) {
[loadingAlert dismissWithClickedButtonIndex:0 animated:true];
}
}
}];
}
// create a string type url
NSString *userTimeString = @"https://api.twitter.com/1.1/statuses/user_timeline.json";
// create SL request for time-line ____________________________
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:userTimeString] parameters:nil];
if (request != nil) {
// user needs to be logged in
[request setAccount:workingAccount];
// perform request
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
// check the response from the server
NSInteger responseCode = [urlResponse statusCode];
if (responseCode == 200) {
// we are good to go
// catch the feed
twitterFeed = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
if (twitterFeed != nil) {
[tweetTableView reloadData];
}
}
else {
NSLog(@"Debugging Error: <the server response is not 200>");
}
}];
}
}
}
}
else {
// debugging: access granted error goes here
NSLog(@"User did not grant access");
}
}];
}
}
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
我想知道在所有信息都加载到我的桌子后是否有办法解除UIAlertView。我查看了Social Framework 的标题,但似乎找不到任何方法(例如:SLRequestDidFinish 或didCompleted)。
【问题讨论】:
标签: iphone objective-c cocoa-touch ios6 ios7