iOS全景浏览App涉及到的技术

一、网络通信

1. 获取服务器数据

AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",nil];
    //拼接请求参数
    NSDictionary *parameter = @{@"user" : @"user",
                                @"title" : @"title",
                                @"description" : @"description",
                                @"panorama" : @"panorama",
                                @"filesize" : @"filesize",
                                @"width" : @"width",
                                @"thumbnail" : @"thumbnail",
                                @"likes" : @"likes",
                                @"collections" : @"collections",
                                @"created" : @"created"
                                };
    // 取出最前面的微博(最新的微博,ID最大的微博)
    HWStatusFrame *firstStatusF = [self.statusFrames firstObject];
    [mgr GET:@"http://114.214.164.105:8000/api/panoramas/" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        //获取相应用户的微博微博字典数组,由于服务器上的是最新发出的排在最后和我们这个微博要求相反,所以要倒过来拿
        NSArray *reverseArray = [[responseObject reverseObjectEnumerator] allObjects];
        //李明杰mj的框架
        /*
         MJExtension是一套字典和模型之间互相转换的超轻量级框架
         MJExtension能完成的功能
         字典(JSON) --> 模型(Model)
         模型(Model) --> 字典(JSON)
         字典数组(JSON Array) --> 模型数组(Model Array)
         模型数组(Model Array) --> 字典数组(JSON Array)
         */
        //这里将字典数组转成模型数组
        /*
         如何从plist中读取字典,并转换成对象模型
         http://www.cnblogs.com/fxiaoquan/archive/2015/04/18/4438126.html
         下面的直接利用第三份开源框架字典转模型工具
         */
        NSArray *newStatuses = [HWStatus mj_objectArrayWithKeyValuesArray:reverseArray];
        //将HWStatus数组转换成HWstatusFrame数组
        NSMutableArray *Frames = [NSMutableArray array];
        //这个newFrames包含所有数据,所以要加上判断
        for(HWStatus *status in newStatuses)
        {
            if(status.created > firstStatusF.status.created)
            {
                HWStatusFrame *f = [[HWStatusFrame alloc] init];
                f.status = status;
                [Frames addObject:f];
            }
            else
                break;
        }
        [self.statusFrames addObjectsFromArray:Frames];
        //可以获取数据
        //NSLog(@"%@",reverseArray);
        //刷新表格
        [self.tableView reloadData];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error == %@",error);
    }];


2.拼接请求参数查看原图

//点击全景图片进行展示,此处用原图
#pragma mark - 代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //获取的全部内容的key
    HWStatusCell *cell = [HWStatusCell cellWithTableView:tableView];
    //statusFrames所有数据模型的集合
    cell.statusFrame = self.statusFrames[indexPath.row];
    //拼url
    NSString *panoString = [NSString stringWithFormat:@"http://114.214.164.105:8000%@",cell.statusFrame.status.panorama];
    PanoViewController *panoView = [[PanoViewController alloc] init];
    panoView.urlString = panoString;
    NSString *biaoti = [NSString stringWithFormat:@"%@",cell.statusFrame.status.title];
    panoView.title = biaoti;
    // 当test1控制器被push的时候,test1所在的tabbarcontroller的tabbar会自动隐藏
    // 当test1控制器被pop的时候,test1所在的tabbarcontroller的tabbar会自动显示
    //    test1.hidesBottomBarWhenPushed = YES;
    
    // self.navigationController === HWNavigationController
    //push进来的会被拦截
    [self.navigationController pushViewController:panoView animated:YES];
    //[self presentViewController:panoView animated:YES completion:nil];
}

3. 上传数据

AFHTTPRequestOperationManager *mgr= [AFHTTPRequestOperationManager manager];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"user"] = @"1";
    params[@"description"] = @"Panoramic Picture";
    params[@"title"] = self.textView.text;
    [mgr POST:@"http://114.214.164.105:8000/api/panoramas/" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        UIImage *image = [self.photosView.photos firstObject];
        NSData *data = UIImageJPEGRepresentation(image, 1.0);
        [formData appendPartWithFileData:data name:@"panorama" fileName:@"PIC" mimeType:@"image/jpeg"];
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [MBProgressHUD showSuccess:@"发送成功"];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD showSuccess:@"发送失败"];
        NSLog(@"%@", self.textView.text);
        NSLog(@"%@", error.localizedDescription);
        NSLog(@"%@", error.localizedFailureReason);
        NSLog(@"%@", error.userInfo);
    }];

二、手写代码而非拖控件需要做的事

下列函数都在AppDelegate中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值