因为sdk里面的属性类缺少以下参数,我需要使用类别,给它添加运营商信息
以下几步,就可以给它追加属性
1、添加类别 TuyaSmartDeviceModel+CarrierInfo
2、添加卡号信息
@interface TuyaSmartDeviceModel (CarrierInfo)
@property (nonatomic , copy)NSString *iccid;//卡号
@property (nonatomic , assign)NSInteger carrierType;
- (void)checkCarrierCardInfo;
@end
3、下面一步是最重要的步骤
#import "TuyaSmartDeviceModel+CarrierInfo.h"
#import <objc/runtime.h>
@implementation TuyaSmartDeviceModel (CarrierInfo)
- (void)checkCarrierCardInfo{
if (self.iccid) {
NSInteger supplier = [[CachCardModelManager sharedInstance]checkSupplierType:self.iccid devid:self.devId];
self.carrierType = supplier;
}
else{
self.carrierType = 0;
}
}
- (void)setIccid:(NSString *)iccid{
objc_setAssociatedObject(self, @selector(iccid), iccid, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (NSString *)iccid{
return objc_getAssociatedObject(self, _cmd);
}
- (void)setCarrierType:(NSInteger)carrierType{
objc_setAssociatedObject(self, @selector(carrierType), @(carrierType), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (NSInteger)carrierType{
return [objc_getAssociatedObject(self, _cmd) integerValue];
}
@end
4、使用 :1> import "TuyaSmartDeviceModel+CarrierInfo.h"
2> 使用它的checkCarrierCardInfo方法