zoukankan      html  css  js  c++  java
  • SimpleWeather APP

    参考

    iOS 7 Best Practices; A Weather App Case Study: Part 1/2

    iOS 7 Best Practices; A Weather App Case Study: Part 2/2

    中文版

    iOS 7最佳实践:一个天气App案例(一)

    iOS 7最佳实践:一个天气App案例(二)

    天气数据源 OpenWeatherMap

    OpenWeatherMap API

    源码

    https://github.com/mobilefeng/SimpleWeather

    2015.7.10

    问题1

    按照Demo,完成了90%,按理说,构建一般,可以获取到位置信息,并显示天气信息

    但是实际运行后无变化

    查到原因如下:

    xcode 6 和 iOS 8 需要获取定位权限

    解决办法:(参考 http://www.cocoachina.com/bbs/read.php?tid-259171.html   5楼的解答)

    1、info.plist里加入对应的缺省字段 ,值设置为YES(前台定位写上边字段,前后台定位写下边字段)

    NSLocationWhenInUseUsageDescription //允许在前台获取GPS的描述

    NSLocationAlwaysUsageDescription //允许在前、后台获取GPS的描述

    2、在 startUpdatingLocation 前面加上获取定位权限代码,系统版本高于8.0,则询问用户定位权限

    - (void)findCurrentLocation {
        self.isFirstUpdate = YES;
        
        if ([[[UIDevice currentDevice] systemVersion] doubleValue] >  8.0) {
            // 前台定位
            [self.locationManager requestWhenInUseAuthorization];
            // 前后台同时定位
    //        [self.locationManager requestAlwaysAuthorization];
        }
        
        [self.locationManager startUpdatingLocation];
    }

    问题2

    修复问题1后,运行,控制台报如下错:

    2015-07-10 21:22:03.060 SimpleWeather[10900:1844013] CUICatalog: Invalid asset name supplied: (null)

    原因:

    排查发现是下面代码出错:

    1 [[RACObserve([WXManager sharedManager], currentCondition)
    2   deliverOn:RACScheduler.mainThreadScheduler]
    3  subscribeNext:^(WXCondition *newCondition) {
    4      temperatureLabel.text = [NSString stringWithFormat:@"%.0f°",newCondition.temperature.floatValue];
    5      conditionsLabel.text = [newCondition.condition capitalizedString];
    6      cityLabel.text = [newCondition.locationName capitalizedString];
    7      
    8      iconView.image = [UIImage imageNamed:[newCondition imageName]];
    9  }];

    在第8行,执行到这一步时,发现newCondition是nil,导致image是空

    但是为何newCondition会是nil,还在排查

    暂时现在block中,加一层判断,

    if (newCondition) {

    // 执行text和image的操作

    }

    问题3

    再次运行,报如下错误:

    2015-07-10 22:49:54.014 SimpleWeather[11128:1866849] *** Assertion failure in -[MTLJSONAdapter initWithModelClass:], /Users/xuyang/Documents/05_iOSPractice/10_SimpleWeather/SimpleWeather/Pods/Mantle/Mantle/MTLJSONAdapter.m:149
    2015-07-10 22:49:54.019 SimpleWeather[11128:1866849] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'windBearing is not a property of WXCondition.'

    原因:

    出错在:

    if (![propertyKeys containsObject:mappedPropertyKey]) {
        NSAssert(NO, @"%@ is not a property of %@.", mappedPropertyKey, modelClass);
        return nil;
    }

    这里的 mappedPropertyKey 是从 WXCondition 中的 JSONKeyPathsByPropertyKey 中得到的

    其中有一项 windBearing(从Demo抄的),在Pod里面没有,导致识别不出

    将 windBearing 改成 windBear即可

    2015.7.11

    问题4

    再次运行,天气数据未刷新,newConditon一直是nil

    原因:

    在原文的回复中有人也遇到这个问题,并给出了解答,是Mantle新的库引入的,解决方法是:

    Great tutorial ! For those who is getting nil newCondition , you need to downgrade "Mantle" , as Bruce Li said it has defect in its latest version . Just close again Xcode , and modify Podfile in terminal as you did it in first part ,
    pico Podfile
    platform :ios, '7.0'
    pod 'Mantle','1.3.1'
    pod 'LBBlurredImage'
    pod 'TSMessages'
    pod 'ReactiveCocoa'
    and then "pod install"

    问题5

    再次运行,提示

    No known class method for selector 'transformerUsingForwardBlock:reverseBlock:

    原因是,之前把Mantle更新到2.0.2(最新版),提示说原来的 reversibleTransformerWithForwardBlock:reverseBlock:不可用了

    于是改用了新的方法,现在回退到1.3.1版本,故要用老方法

    http://stackoverflow.com/questions/29594029/reversibletransformerwithforwardblock-is-deprecated

    这里有关于这两个方法的说明

    2015.7.12

    问题6

    现在显示的时间是0时区的时间,想要显示成北京时间(东八区)

    方法:

    在dateFormatter初始化时,设置一下时区

    [_hourlyFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    [_dailyFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CH"]];

    问题7

    我将 dateFormat 设置成 @"HH:mm" 后,发现现实的时间,有些出现20:01或23:59这样的时间

    原因:

    // NSString <-> NSDate
    + (NSValueTransformer *)dateJSONTransformer {
        return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSString *str) {
            return [NSDate dateWithTimeIntervalSince1970:str.doubleValue];
        } reverseBlock:^(NSDate *date) {
            return [NSString stringWithFormat:@"%f", [date timeIntervalSince1970]];
        }];
    }

    str.floatValue --> str.doubleValue

    float精度不够,导致末位可能被四舍五入导致的

    这个问题BDN APP中RD曾经犯过

  • 相关阅读:
    Odoo开发教程15-管理 Odoo 数据库
    星辉信息科技Odoo开发教程14-源码安装 Odoo第三讲
    星辉信息科技Odoo开发教程13-源码安装 Odoo第二讲
    Odoo开发教程12-源码安装 Odoo
    星辉信息科技Odoo开发教程11-使用 Windows 子系统安装 Linux
    Metasploit 进阶
    Metasploit 一些重要模块使用介绍
    Metasploit 使用基础
    【译】Attacking XML with XML External Entity Injection (XXE)
    CentOS6 安装Sendmail + Dovecot + Roundcubemail
  • 原文地址:https://www.cnblogs.com/mobilefeng/p/4622035.html
Copyright © 2011-2022 走看看