业务方案

iOS工作开发问题总结纪录 长期更新

2018-05-31  本文已影响1人  iii余光

今天开贴大吉 长期更新~

意在记录一些开发中遇到的问题和处理方式方法 以鉴需要的人

APP icon 在iPhone上可以显示 但在iPad上显示不出来

解决方法:在info.plist里删除CFBundleIcons~ipad 这个Key
iPhone项目在iPad中无法显示图标解决方法

生成标准的整套iOS App icon 图片(无alpha通道)

应用的图标。遵循 AppleGoogleMicrosoft 官方标
图片工厂— 移动应用图标生成工具,一键生成所有尺寸的应用图标

Object/Model对象储存到NSUserDefaults
//序列化对象并储存
LHPersonModel *personModel = [[LHPersonModel alloc]init];
NSData *personData = [NSKeyedArchiver archivedDataWithRootObject: LHPersonModel];
[[NSUserDefaults standardUserDefaults] setObject:personData forKey:@"KPersonData"];
//取出数据并反序列化
NSData *personData = [[NSUserDefaults standardUserDefaults] objectForKey:@"KPersonData"];    
LHPersonModel * personModel = [NSKeyedUnarchiver unarchiveObjectWithData:personData];    
NSLog(@"Name:%@ Age:%@", personModel.name, @(personModel.age));
账号/密码/用户名 去除左右两侧空格

产品反馈 有用户前后多输入空格导致无法登录 空格肉眼又看不见 so 需要过滤左右空格(中间空格不过滤)让用户可以登录

NSString* str = @" 15910221559@163.com    ";     
NSString* res = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];  

iOS和Android去除字符串两边的空格

MKMapvie iOS苹果系统地图 获取比例尺&罗盘 更改其坐标(支持iOS11+)
//比例尺
- (void)setMapScaleBarPosition:(CGPoint)mapScaleBarPosition
{
    if (@available(iOS 11.0, *)) {
        __block MKScaleView *  mapScaleView = [self.mapView viewWithTag:11 * 11];
        if ( mapScaleView == nil) {
            mapScaleView = [MKScaleView scaleViewWithMapView:_mapView];
            mapScaleView.scaleVisibility = MKFeatureVisibilityVisible;
            mapScaleView.tag = 11 * 11;
            mapScaleView.width = 100;
            [self.mapView addSubview:mapScaleView];
        }
        
        [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
            mapScaleView.origin = mapScaleBarPosition;
        } completion:nil];

    } else {
//            _mapView.showsScale = YES;
        // Fallback on earlier versions
    }
}
//罗盘
- (void)setMapCompassPosition:(CGPoint)mapCompassPosition
{
    if (@available(iOS 11.0, *)) {
        MKCompassButton *compass = [MKCompassButton compassButtonWithMapView:(MKMapView *)self.mapView];
        compass.compassVisibility = MKFeatureVisibilityAdaptive;
        compass.origin = mapCompassPosition;
        compass.tag = 12 * 12;
        [self.mapView addSubview:compass];
    } else {
//        _mapView.showsCompass = YES;
        // Fallback on earlier versions
    }
}
百度坐标、国测局坐标、地球坐标之间的互转纠偏
//百度坐标转国测局坐标
+ (CLLocationCoordinate2D)baiduToGCJ02Tool:(CLLocationCoordinate2D)coodinate
{
    double x = coodinate.longitude - 0.0065, y = coodinate.latitude - 0.006;
    double z = sqrt(x * x + y * y) - 0.00002 * sin(y * earth_pi);
    double theta = atan2(y, x) - 0.000003 * cos(x * earth_pi);
    double lon = z * cos(theta);
    double lat = z * sin(theta);
    
    return CLLocationCoordinate2DMake(lat, lon);
}

//国测局坐标转百度坐标
+ (CLLocationCoordinate2D)GCJ02ToBaidu:(CLLocationCoordinate2D)coodinate
{
  double x = coodinate.longitude;
  double y = coodinate.latitude;
  double z = sqrt(x * x + y * y) + 0.00002 * sin(y * earth_pi);
  double theta = atan2(y, x) + 0.000003 * cos(x * earth_pi);
  
  double lon = z * cos(theta) + 0.0065;
  double lat = z * sin(theta) + 0.006;
  
  return CLLocationCoordinate2DMake(lat, lon);
}
//地球坐标转国测局坐标
+ (CLLocationCoordinate2D)earthToGCJ02Tool:(CLLocationCoordinate2D)coodinate{
    double dLat = [self transformLatWithLon:coodinate.longitude - 105.0 andLat:coodinate.latitude - 35.0];
    double dLon = [self transformLonWithLon:coodinate.longitude - 105.0 andLat:coodinate.latitude - 35.0];
    double radLat = coodinate.latitude / 180.0 * math_pi;
    double magic = sin(radLat);
    magic = 1 - de * magic * magic;
    double sqrtMagic = sqrt(magic);
    dLat = (dLat * 180.0) / ((a * (1 - de)) / (magic * sqrtMagic) * math_pi);
    dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * math_pi);
    
    return CLLocationCoordinate2DMake(coodinate.latitude + dLat, coodinate.longitude + dLon);
}

const double math_pi = 3.14159265358979324;
const double earth_pi = 3.14159265358979324 * 3000.0 / 180.0;
const double a = 6378245.0;
const double de = 0.00669342162296594323;
+ (double)transformLatWithLon:(double)x andLat:(double)y
{
  double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(fabs(x));
  ret += (20.0 * sin(6.0 * x * math_pi) + 20.0 * sin(2.0 * x * math_pi)) * 2.0 / 3.0;
  ret += (20.0 * sin(y * math_pi) + 40.0 * sin(y / 3.0 * math_pi)) * 2.0 / 3.0;
  ret += (160.0 * sin(y / 12.0 * math_pi) + 320 * sin(y * math_pi / 30.0)) * 2.0 / 3.0;
  return ret;
}

//国测局坐标转地球坐标
+ (CLLocationCoordinate2D)GCJ02ToEarthTool:(CLLocationCoordinate2D)coodinate
{
    double dLat = [self transformLatWithLon:coodinate.longitude - 105.0 andLat:coodinate.latitude - 35.0];
    double dLon = [self transformLonWithLon:coodinate.longitude - 105.0 andLat:coodinate.latitude - 35.0];
    double radLat = coodinate.latitude / 180.0 * math_pi;
    double magic = sin(radLat);
    magic = 1 - de * magic * magic;
    double sqrtMagic = sqrt(magic);
    dLat = (dLat * 180.0) / ((a * (1 - de)) / (magic * sqrtMagic) * math_pi);
    dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * math_pi);
    
    return CLLocationCoordinate2DMake(coodinate.latitude - dLat, coodinate.longitude - dLon);
}

.......

iOS 判断当前经纬度位置coordinate 是否在中国大陆、中国台湾、中国香港

(iOS)判断GPS坐标是否在中国

推荐一个练习刷算法题的网站 现在也有了中国版 很nice的

LeetCode 中国

run-ios React Native 运行时报错

Found Xcode project AwesomeProject.xcodeproj
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH

Command failed: xcrun simctl list devices
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH

Xcode工具路径不对 应该是你装过两个Xcode 或者改过路径 去Xcode>preferences>Locations command line tools:

屏幕快照 2018-06-12 下午8.23.44.png
React-native 报错集合

如果你正在学习入门RN 建议可以遇到error可以看一下这篇文章 新手遇到的问题这里都有列举 还有其他问题可以留言 一起讨论
React Native开发错误警告处理总结

上一篇 下一篇

猜你喜欢

热点阅读