
- (void)demoWebServiceBinding
{
SCWebServiceDefinition *itunesDef = [SCWebServiceDefinition definitionWithBaseURL:@"https://itunes.apple.com/"
fetchObjectsAPI:@"lookup"
resultsKeyName:@"results"
resultsDictionaryKeyNamesString:@"trackName;sellerName;releaseDate"];
[itunesDef.fetchObjectsParameters setValue:@"504xxx87" forKey:@"id"]; // Your Team ID
[itunesDef.fetchObjectsParameters setValue:@"us" forKey:@"country"]; // Country
[itunesDef.fetchObjectsParameters setValue:@"software" forKey:@"entity"]; // Category is software
SCPropertyDefinition *textPropertyDef = [itunesDef propertyDefinitionWithName:@"trackName"];
textPropertyDef.title = @"App Name";
textPropertyDef.type = SCPropertyTypeTextView;
SCPropertyDefinition *userPropertyDef = [itunesDef propertyDefinitionWithName:@"sellerName"];
userPropertyDef.title = @"Seller Name";
userPropertyDef.type = SCPropertyTypeLabel;
SCPropertyDefinition *tweetedAtPropertyDef = [itunesDef propertyDefinitionWithName:@"releaseDate"];
tweetedAtPropertyDef.title = @"Release At";
tweetedAtPropertyDef.type = SCPropertyTypeLabel;
// Add tweets section
SCArrayOfObjectsSection *itunesSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil webServiceDefinition:itunesDef];
itunesSection.itemsAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
itunesSection.allowAddingItems = NO;
itunesSection.allowDeletingItems = NO;
itunesSection.allowEditDetailView = NO;
itunesSection.allowMovingItems = NO;
itunesSection.sectionActions.didFetchItemsFromStore = ^(SCArrayOfItemsSection *itemsSection, NSMutableArray *items)
{
// Add a button cell at the end of the items list
if (items.count > 1)
[items removeObjectAtIndex:0]; // First entry is a fake so we delete it from data store!
};
itunesSection.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
// Get app link and open it in AppStore
id boundObject = cell.boundObject;
if ([boundObject isKindOfClass:[NSDictionary class]]) {
NSString *applink = [(NSDictionary *)boundObject objectForKey:@"trackViewUrl"];
if (applink) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:applink]];
}
}
};
itunesSection.sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath){
SCCustomCell *cell = [SCCustomCell cellWithText:nil
objectBindingsString:@"1:artworkUrl60;2:trackName;3:sellerName" // 1,2,3 is views' tag
nibName:@"TweetCell"];
return cell;
};
[self.tableViewModel addSection:itunesSection];
// Enable pull-to-refresh
self.tableViewModel.enablePullToRefresh = YES;
}
Edited by devia, 22 January 2013 - 07:07 PM.