项目总结(一)

  • 圆角阴影的使用导致界面卡顿尤其是在UICollectionView和UITableView中的使用,以下代码大部分情况下可以马上把你的帧数提高在55帧每秒以上,它会使视图渲染内容被缓存起来,下次绘制的时候可以直接显示缓存,当然要在视图内容不改变的情况下。
self.layer.shouldRasterize = YES;  
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
  • 同时实现阴影和圆角(弄一个和图片大小一样的view,然后把UIImageView放到里面,代码如下)
self.headImage.layer.cornerRadius = 10;
    self.headImage.layer.masksToBounds = YES;
    
    self.shadowView.layer.shadowColor = RGB(40, 45, 65).CGColor;
    self.shadowView.layer.shadowOffset = CGSizeMake(1, 2);
    self.shadowView.layer.shadowOpacity = 0.1;
    self.shadowView.layer.shadowRadius = 4.0;
    self.shadowView.layer.cornerRadius = 4.0;
    self.shadowView.clipsToBounds = NO;
  • 使用 plist 存储的自定义对象时需要注意得时取出来的对象为不可变的,直接修改可能失败报错
    存储自定义对象要进行编解码把需要存储的数据转换为NSData类型,取出来的时候再将NSData转换成自己的类型 Model需要继承NSCoding,实现以下方法
/** 给自定义Model进行编码 */
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.ID forKey:@"id"];
    [aCoder encodeObject:self.userCode forKey:@"userCode"];
    [aCoder encodeObject:self.userName forKey:@"userName"];
    [aCoder encodeObject:self.password forKey:@"password"];
    [aCoder encodeObject:self.status forKey:@"status"];
    [aCoder encodeObject:self.createTime forKey:@"createTime"];
    [aCoder encodeObject:self.mobileNumber forKey:@"mobileNumber"];
    [aCoder encodeObject:self.headImageName forKey:@"headImageName"];
    [aCoder encodeBool:self.isOnWiFiDownLoad forKey:@"isOnWiFiDownLoad"];
    [aCoder encodeBool:self.isAcceptInfo forKey:@"isAcceptInfo"];
}

/** 使用的时候还要进行解码 */
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
        self.ID = [aDecoder decodeObjectForKey:@"id"];
        self.userCode = [aDecoder decodeObjectForKey:@"userCode"];
        self.userName = [aDecoder decodeObjectForKey:@"userName"];
        self.password = [aDecoder decodeObjectForKey:@"password"];
        self.status = [aDecoder decodeObjectForKey:@"status"];
        self.createTime = [aDecoder decodeObjectForKey:@"createTime"];
        self.mobileNumber = [aDecoder decodeObjectForKey:@"mobileNumber"];
        self.headImageName = [aDecoder decodeObjectForKey:@"headImageName"];
        self.isAcceptInfo = [aDecoder decodeBoolForKey:@"isAcceptInfo"];
        self.isOnWiFiDownLoad = [aDecoder decodeBoolForKey:@"isOnWiFiDownLoad"];
    }
    return self;
}

如果需要修改存储到plist 文件中的自定义模型的数据,必须要把从plist文件中取出来的自定义对象变为可变对象,这样操作才会有效,把不可变对象变为可变对象 需要使Model继承NSMutableCopying 实现以下方法

- (id)mutableCopyWithZone:(NSZone *)zone{
    FXUserInfoModel *model = [[FXUserInfoModel allocWithZone:zone] init];
    model.ID = self.ID;
    model.userCode = self.userCode;
    model.userName =  self.userName;
    model.password =  self.password;
    model.status    =self.status;
    model.createTime = self.createTime;
    model.mobileNumber = self.mobileNumber;
    model.headImageName = self.headImageName;
    model.isAcceptInfo = self.isAcceptInfo;
    model.isOnWiFiDownLoad = self.isOnWiFiDownLoad;
    return model;
}
  • 具体操作:
/** 从plist 中取出自定义对象*/
 FXUserInfoModel *model = [[FXManager loadCustomObjectWithKey:[NSString stringWithFormat:@"%@+%@",@"FXUserInfoModel",[UserDefaultsUtils valueWithKey:@"userID"]]] mutableCopy];

/** 修改从plist中取出来的值 */
model.isOnWiFiDownLoad = NO;

/** 把修改后的值重新存回去 */
 [FXManager saveCustomObject:model withKey:[NSString stringWithFormat:@"%@+%@",@"FXUserInfoModel",[UserDefaultsUtils valueWithKey:@"userID"]]];

······完美解决
  • 如何实现互斥登陆,即同一账号只能同时在线一个用户,实现原理,服务器+友盟推送 实现同时只能在线一个账号
  1. 移动端需要我们设置HTTP请求头,给请求头传入和服务器端事先约定好的参数,这里我们传入两个参数:apiKey ,userId。第一个参数传注册友盟推送的时候系统回调传回来的deviceToken 这个参数是为了让后太推送确定把消息推送给指定的被下线的用户,第二个参数是为了确定用户的ID登录状态,我们还需要监听收到的通知,届时让服务器端配置一个自定义参数用于识别是否是下线通知,如果是,我们在当前界面做出响应,提示用户已下线。2.服务器端根据请求头的数据做出是否推送消息的动作,如果需要推送消息,则发送与移动端约定好的识别参数的通知。 具体代码如下
/** 第一步 在Application.m获取手机注册成功友盟推送回调得到deviceToken并保存 */
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSString *deviceTokenStr = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
                                             stringByReplacingOccurrencesOfString: @">" withString: @""]
                                            stringByReplacingOccurrencesOfString: @" " withString: @""];
    
    [UserDefaultsUtils saveValue:deviceTokenStr forKey:@"apiKey"];
    NSDictionary *parameters = [[NSMutableDictionary alloc] init];
    NSString *userStr =[NSString stringWithFormat:@"%@",[UserDefaultsUtils valueWithKey:@"userID"]];
    if (!userStr || [userStr isEqualToString:@""]) {
        [parameters setValue:userStr forKey:@"userId"];
    }else{
        [parameters setValue:@"" forKey:@"userId"];
    }
    [parameters setValue:[UserDefaultsUtils valueWithKey:@"apiKey"] forKey:@"apiKey"];
    /** 动态设置请求头必须每次调用 updateBaseUrl 方法*/
    [HYBNetworking updateBaseUrl:BaseUrl];
    [HYBNetworking configCommonHttpHeaders:parameters];
}

/** 在前后台收到通知的时候判断是否为下线通知,如果是提示用户已下线,并且退出当前账号 */
//iOS10新增:处理前台收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //应用处于前台时的远程推送接受
        //关闭U-Push自带的弹出框
        [UMessage setAutoAlert:NO];
        //必须加这句代码
        [UMessage didReceiveRemoteNotification:userInfo];
        
        if ([userInfo[@"operationError"] isEqualToString:@"1001"]) {
            UIAlertController *alercConteoller = [UIAlertController alertControllerWithTitle:@"提示" message:@"当前账号已在其他设备登录,您已被迫下线" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [self signOutCurrentAccount];
            }];
            [alercConteoller addAction:actionYes];
            [[FXManager getCurrentVC] presentViewController:alercConteoller animated:YES completion:nil];
        }
        
    }else{
        //应用处于前台时的本地推送接受
    }
    //当应用处于前台时提示设置,需要哪个可以设置哪一个
    completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
}

//iOS10新增:处理后台点击通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //应用处于后台时的远程推送接受
        //必须加这句代码
        [UMessage didReceiveRemoteNotification:userInfo];
        if ([userInfo[@"operationError"] isEqualToString:@"1001"]) {
            UIAlertController *alercConteoller = [UIAlertController alertControllerWithTitle:@"提示" message:@"当前账号已在其他设备登录,您已被迫下线" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [self signOutCurrentAccount];
            }];
            [alercConteoller addAction:actionYes];
            [[FXManager getCurrentVC] presentViewController:alercConteoller animated:YES completion:nil];
        }
    }else{
        //应用处于后台时的本地推送接受
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,591评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,448评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,823评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,204评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,228评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,190评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,078评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,923评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,334评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,550评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,727评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,428评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,022评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,672评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,826评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,734评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,619评论 2 354

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,079评论 25 707
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,652评论 18 139
  • 点击查看原文 Web SDK 开发手册 SDK 概述 网易云信 SDK 为 Web 应用提供一个完善的 IM 系统...
    layjoy阅读 13,758评论 0 15
  • “君韶,如果没有月尚白,或许你就不会这么可怜了。”君烟疏居高临下的看着被人压在地上的我,眼中满是讥讽。 我嫌恶的甩...
    执年就是依晗曦阅读 253评论 0 2
  • 今天,我们说说英雄故事的套路 我走过的最远的路,就是那些个编故事的家伙的套路 其实这些套路也可以用到演示上来(宅宅...
    肥宅V阅读 205评论 0 1