dimanche 1 février 2015

iOS: Twitter Paging adding more Tweets

I am attempting to add Pagination to my Twitter Client on iOS using AFNetworking. However when I run the method to get the tweets I get this error:



2015-02-01 15:39:47.428 Floadt[49165:2116574] CRASH :
-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object
2015-02-01 15:39:47.429 Floadt[49165:2116574] STACK TRACE :
(
0 CoreFoundation 0x00000001101f2f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010fe8bbb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001101f2e6d +[NSException raise:format:] + 205
3 CoreFoundation 0x00000001101eb6ea -[__NSCFArray insertObject:atIndex:] + 106
4 CoreFoundation 0x0000000110117a43 -[NSMutableArray insertObjects:count:atIndex:] + 179
5 CoreFoundation 0x0000000110117774 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 372
6 CoreFoundation 0x0000000110117574 -[NSMutableArray addObjectsFromArray:] + 612
7 Floadt 0x000000010cadc9ac __57-[TwitterTableViewController fetchNextTwitterPageWithID:]_block_invoke + 188
8 Floadt 0x000000010cabdcc3 __64-[AFJSONRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke91 + 51
9 libdispatch.dylib 0x000000011234cba6 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x000000011236a7f4 _dispatch_client_callout + 8
11 libdispatch.dylib 0x00000001123538fb _dispatch_main_queue_callback_4CF + 949
12 CoreFoundation 0x000000011015afe9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
13 CoreFoundation 0x000000011011deeb __CFRunLoopRun + 2043
14 CoreFoundation 0x000000011011d486 CFRunLoopRunSpecific + 470
15 GraphicsServices 0x0000000111b7a9f0 GSEventRunModal + 161
16 UIKit 0x000000010ebd3420 UIApplicationMain + 1282
17 Floadt 0x000000010cb30ed3 main + 115
18 libdyld.dylib 0x000000011239f145 start + 1
19 ??? 0x0000000000000001 0x0 + 1
)


Here is my method to get the older tweets:



-(void)fetchNextTwitterPageWithID:(NSString *)objectID {
self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"http://ift.tt/YFagLh"] key:@"XXXXXX" secret:@"XXXXXX"];

NSDictionary *parameters = @{
@"max_id" :objectID
};

AFOAuth1Token *twitterToken = [AFOAuth1Token retrieveCredentialWithIdentifier:@"TwitterToken"];
[self.twitterClient setAccessToken:twitterToken];
[self.twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self.twitterClient getPath:@"statuses/home_timeline.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSMutableArray *responseArray = (NSMutableArray *)responseObject;
//NSLog(@"Response: %@", responseObject);
tweets = [tweets copy];
[tweets addObjectsFromArray:responseArray];
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}


Here is my method to detect that the User reached the bottom of the table view (this works perfectly fine):



-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tweets count] == (indexPath.row+1)) {
NSDictionary *totalArray = tweets[indexPath.row];
NSString *cellID = [totalArray objectForKey:@"id"];
NSLog(@"%@",cellID);
[self fetchNextTwitterPageWithID:cellID];
}
}



Aucun commentaire:

Enregistrer un commentaire