Ios 合并2个NSURL会话,以便我可以将其中两张instagram用户的照片合并在一起
如您所见,我有两种方法Ios 合并2个NSURL会话,以便我可以将其中两张instagram用户的照片合并在一起,ios,instagram,nsurl,Ios,Instagram,Nsurl,如您所见,我有两种方法tuula和wendyslookbook。然后我在我的mostPopular方法中调用它们。我已经从Instagram API请求了这些照片,但现在我想把这两张用户照片放在一起。我该怎么做 // // PhotosViewController.m // Photo Bombers // // Created by Alex Macleod on 20/8/14. // Copyright (c) 2014 Alex Macleod. All rights reser
tuula
和wendyslookbook
。然后我在我的mostPopular
方法中调用它们。我已经从Instagram API请求了这些照片,但现在我想把这两张用户照片放在一起。我该怎么做
//
// PhotosViewController.m
// Photo Bombers
//
// Created by Alex Macleod on 20/8/14.
// Copyright (c) 2014 Alex Macleod. All rights reserved.
//
#import "PhotosViewController.h"
#import "PhotoCell.h"
#import "DetailViewController.h"
#import "PresentDetailTransition.h"
#import "DismissDetailTransition.h"
#import <SimpleAuth/SimpleAuth.h>
@interface PhotosViewController () <UIViewControllerTransitioningDelegate>
@property (nonatomic) NSString *accessToken;
@property (nonatomic) NSArray *photos;
@end
@implementation PhotosViewController
- (instancetype) init {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
layout.itemSize = CGSizeMake(106.0, 106.0);
layout.minimumInteritemSpacing = 1.0;
layout.minimumLineSpacing = 1.0;
return (self = [super initWithCollectionViewLayout:layout]);
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Fashun";
[self.collectionView registerClass:[PhotoCell class] forCellWithReuseIdentifier:@"photo"];
self.collectionView.backgroundColor = [UIColor whiteColor];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
self.accessToken = [userDefaults objectForKey:@"accessToken"];
if (self.accessToken == nil) {
[SimpleAuth authorize:@"instagram" options:@{@"scope": @[@"likes"]} completion:^(NSDictionary *responseObject, NSError *error) {
self.accessToken = responseObject[@"credentials"][@"token"];
[userDefaults setObject:self.accessToken forKey:@"accessToken"];
[userDefaults synchronize];
[self mostPopular];
}];
} else {
[self mostPopular];
}
}
- (void)tuula {
NSURLSession *session = [NSURLSession sharedSession];
NSString *urlString = [[NSString alloc]initWithFormat:@"https://api.instagram.com/v1/users/7522782/media/recent/?access_token=%@", self.accessToken];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSLog(@"links: %@", location);
NSData *data = [[NSData alloc]initWithContentsOfURL:location];
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
self.photos = [responseDictionary valueForKeyPath:@"data"];
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView reloadData];
});
}];
[task resume];
}
- (void)wendyslookbook {
NSURLSession *session = [NSURLSession sharedSession];
NSString *urlString = [[NSString alloc]initWithFormat:@"https://api.instagram.com/v1/users/14454619/media/recent/?access_token=%@", self.accessToken];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSLog(@"links: %@", location);
NSData *data = [[NSData alloc]initWithContentsOfURL:location];
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
self.photos = [responseDictionary valueForKeyPath:@"data"];
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView reloadData];
});
}];
[task resume];
}
- (void)mostPopular {
[self tuula];
[self wendyslookbook];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.photos count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
PhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"photo" forIndexPath:indexPath];
cell.backgroundColor = [UIColor lightGrayColor];
cell.photo = self.photos[indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *photo = self.photos[indexPath.row];
DetailViewController *viewController = [[DetailViewController alloc]init];
viewController.modalPresentationStyle = UIModalPresentationCustom;
viewController.transitioningDelegate = self;
viewController.photo = photo;
[self presentViewController:viewController animated:YES completion:nil];
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
return [[PresentDetailTransition alloc]init];
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
return [[DismissDetailTransition alloc]init];
}
@end
//
//PhotosViewController.m
//照片轰炸机
//
//亚历克斯·麦克劳德于2014年8月20日创作。
//版权所有(c)2014亚历克斯·麦克劳德。版权所有。
//
#导入“PhotosViewController.h”
#导入“PhotoCell.h”
#导入“DetailViewController.h”
#导入“PresentDetailTransition.h”
#导入“DismissDetailTransition.h”
#进口
@接口视图控制器()
@属性(非原子)NSString*accessToken;
@财产(非原子)NSArray*照片;
@结束
@视图控制器的实现
-(instancetype)初始化{
UICollectionViewFlowLayout*布局=[[UICollectionViewFlowLayout alloc]init];
layout.itemSize=CGSizeMake(106.0,106.0);
layout.minimumInteritemSpacing=1.0;
layout.minimumLineSpacing=1.0;
返回(self=[super initWithCollectionViewLayout:layout]);
}
-(无效)viewDidLoad{
[超级视图下载];
self.title=@“发顺”;
[self.collectionView注册表类:[PhotoCell类]forCellWithReuseIdentifier:@“photo”];
self.collectionView.backgroundColor=[UIColor whiteColor];
NSUserDefaults*userDefaults=[NSUserDefaults standardUserDefaults];
self.accessToken=[userDefaults objectForKey:@“accessToken”];
if(self.accessToken==nil){
[SimpleAuthorization:@“instagram”选项:@{“scope”:@[@“likes”}完成:^(NSDictionary*responseObject,NSError*错误){
self.accessToken=responseObject[@“credentials”][@“token”];
[userDefaults setObject:self.accessToken forKey:@“accessToken”];
[用户默认同步];
[自我最普遍];
}];
}否则{
[自我最普遍];
}
}
-(无效)图拉{
NSURLSession*会话=[NSURLSession sharedSession];
NSString*urlString=[[NSString alloc]initWithFormat:@”https://api.instagram.com/v1/users/7522782/media/recent/?access_token=%@“,self.accessToken];
NSURL*url=[[NSURL alloc]initWithString:urlString];
NSURLRequest*request=[[NSURLRequest alloc]initWithURL:url];
NSURLSessionDownloadTask*任务=[session downloadTaskWithRequest:request completionHandler:^(NSURL*位置,NSURResponse*响应,NSError*错误){
NSLog(@“链接:%@”,位置);
NSData*data=[[NSData alloc]initWithContentsOfURL:location];
NSDictionary*responseDictionary=[NSJSONSerialization JSONObjectWithData:数据选项:编织错误:nil];
self.photos=[responseDictionary valueForKeyPath:@“data”];
dispatch\u async(dispatch\u get\u main\u queue()^{
[self.collectionView-reloadData];
});
}];
[任务恢复];
}
-(作废)wendyslookbook{
NSURLSession*会话=[NSURLSession sharedSession];
NSString*urlString=[[NSString alloc]initWithFormat:@”https://api.instagram.com/v1/users/14454619/media/recent/?access_token=%@“,self.accessToken];
NSURL*url=[[NSURL alloc]initWithString:urlString];
NSURLRequest*request=[[NSURLRequest alloc]initWithURL:url];
NSURLSessionDownloadTask*任务=[session downloadTaskWithRequest:request completionHandler:^(NSURL*位置,NSURResponse*响应,NSError*错误){
NSLog(@“链接:%@”,位置);
NSData*data=[[NSData alloc]initWithContentsOfURL:location];
NSDictionary*responseDictionary=[NSJSONSerialization JSONObjectWithData:数据选项:编织错误:nil];
self.photos=[responseDictionary valueForKeyPath:@“data”];
dispatch\u async(dispatch\u get\u main\u queue()^{
[self.collectionView-reloadData];
});
}];
[任务恢复];
}
-(无效)大多数人{
[自我推拉];
[self wendyslookbook];
}
-(NSInteger)collectionView:(UICollectionView*)collectionView项目编号截面:(NSInteger)截面{
返回[self.photos count];
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
PhotoCell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:@“photo”forIndexPath:indexPath];
cell.backgroundColor=[UIColor lightGrayColor];
cell.photo=self.photos[indexPath.row];
返回单元;
}
-(void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
NSDictionary*photo=self.photos[indexPath.row];
DetailViewController*viewController=[[DetailViewController alloc]init];
viewController.modalPresentationStyle=UIModalPresentationCustom;
viewController.transitioningDelegate=self;
viewController.photo=照片;
[self-presentViewController:viewController动画:是完成:无];
}
-(id)显示了animationControllerForPresentedController:(UIViewController*)
呈现控制器:(UIViewController*)呈现
sourceController:(UIViewController*)源{
返回[[PresentDetailTransition alloc]init];
}
-(id)animationControllerForDismissedController:(UIViewController*)已解除{
返回[[DismissDetailTransition alloc]init];
}
@结束
一次只显示一个用户,这太烦人了!分别下载它们,并使用您正在使用的任何成像技术来组合它们。为什么你认为网络会话需要合并?那没有道理。