This commit is contained in:
wushenghua
2016-01-20 18:16:28 +08:00
parent e0bbd64444
commit dea9306931
13 changed files with 163 additions and 224 deletions
+5 -3
View File
@@ -91,23 +91,25 @@ Pod::Spec.new do |s|
s.source_files = 'WlianWorld/Model/*','WlianWorld/Util/**/*','WlianWorld/View/*','WlianWorld/ViewModel/*','WlianWorld/Config/*'
# s.exclude_files = "Classes/Exclude"
s.public_header_files = 'WlianWorld/Config/*.{h}','WlianWorld/Model/*.{h}','WlianWorld/Util/*.{h}'
s.prefix_header_file = 'WlianWorld/PrefixHeader.pch'
s.frameworks = "UIKit"
s.dependency 'Mantle'
s.dependency 'AFNetworking', '~> 2.5.4'
s.dependency 'DTCoreText', '~>1.6.17'
s.dependency 'EGOCache', '~>2.13'
s.dependency 'EGOCache'
s.dependency 'Godzippa', '~>1.1.0'
s.dependency 'MBProgressHUD', '~>0.9.2'
s.dependency 'MJRefresh', '~>3.1.0'
s.dependency 'Reachability', '~>3.2'
s.dependency 'ReactiveCocoa', '~>2.5'
s.dependency 'SDWebImage', '~>3.7.4'
s.dependency 'SecureUDID', '~>1.1'
# s.dependency 'SecureUDID', '~>1.1'
s.dependency 'STableViewController', '~>0.0.1'
s.dependency 'SVWebViewController', '~>1.0'
s.dependency 'SBJson', '~>4.0.2'
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
@@ -3,54 +3,6 @@
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WlianWorld/Model/BaseWLService.m"
timestampString = "469096535.078965"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "69"
endingLineNumber = "69"
landmarkName = "+requireWithGetWithProperty:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WlianWorld/Model/BaseWLService.m"
timestampString = "469096536.720861"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "67"
endingLineNumber = "67"
landmarkName = "+requireWithGetWithProperty:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WlianWorld/Model/BaseWLService.m"
timestampString = "469096539.285181"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "74"
endingLineNumber = "74"
landmarkName = "+requireWithGetWithProperty:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
@@ -96,9 +96,9 @@
"scale" : "2x"
},
{
"idiom" : "car",
"size" : "120x120",
"scale" : "1x"
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"size" : "24x24",
@@ -153,6 +153,11 @@
"scale" : "2x",
"role" : "quickLook",
"subtype" : "42mm"
},
{
"idiom" : "car",
"size" : "120x120",
"scale" : "1x"
}
],
"info" : {
+7 -8
View File
@@ -7,28 +7,27 @@
//
#import "BaseAPIClient.h"
#import "Common.h"
@implementation BaseAPIClient
+ (instancetype)sharedClient
{
static BaseAPIClient *_sharedClient = nil;
static BaseAPIClient* _sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[BaseAPIClient alloc] initWithBaseURL:[NSURL URLWithString:[self getApiBaseString]]];
_sharedClient.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[_sharedClient.requestSerializer setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
_sharedClient.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
});
return _sharedClient;
}
+ (NSString *)getApiBaseString
+ (NSString*)getApiBaseString
{
return WL_DEV_API_URL;
return WL_DEV_API_URL;
}
@end
+4 -5
View File
@@ -7,11 +7,10 @@
//
#import <Foundation/Foundation.h>
@interface BaseModel : MTLModel <MTLJSONSerializing>
@interface BaseModel : MTLModel<MTLJSONSerializing>
@property (nonatomic,strong)NSString* title;
@property (nonatomic,readonly)NSString* errorCode;
@property (nonatomic,readonly)NSString* errorMessage;
@property (nonatomic, strong) NSString* title;
@property (nonatomic, readonly) NSString* errorCode;
@property (nonatomic, readonly) NSString* errorMessage;
@end
+27 -26
View File
@@ -7,40 +7,41 @@
//
#import "BaseModel.h"
@implementation BaseModel
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
+ (NSDictionary*)JSONKeyPathsByPropertyKey
{
return @{
// @"errCode": @"ret",
@"errorCode": @"errorCode",
@"errorMessage": @"errorMessage",
};
// @"errCode": @"ret",
@"errorCode" : @"errorCode",
@"errorMessage" : @"errorMessage",
};
}
+ (NSValueTransformer *)errorCodeJSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^id(id value,BOOL *success, NSError *__autoreleasing *error) {
NSNumber *num = value;
NSString *tempStr = [NSString stringWithFormat:@"%@", num];
+ (NSValueTransformer*)errorCodeJSONTransformer
{
return [MTLValueTransformer transformerUsingForwardBlock:^id(id value, BOOL* success, NSError* __autoreleasing* error) {
NSNumber* num = value;
NSString* tempStr = [NSString stringWithFormat:@"%@", num];
return tempStr;
} reverseBlock:^id(id value,BOOL *success, NSError *__autoreleasing *error) {
NSString *tempStr = value;
NSNumber *tempNum = @(tempStr.integerValue);
return tempNum;
}];
}
reverseBlock:^id(id value, BOOL* success, NSError* __autoreleasing* error) {
NSString* tempStr = value;
NSNumber* tempNum = @(tempStr.integerValue);
return tempNum;
}];
}
- (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error
- (instancetype)initWithDictionary:(NSDictionary*)dictionaryValue error:(NSError**)error
{
self = [super initWithDictionary:dictionaryValue error:error];
if (self != nil)
{
if (self != nil) {
}
return self;
}
+49 -58
View File
@@ -6,95 +6,86 @@
// Copyright © 2015年 ash. All rights reserved.
//
#import "BaseWLService.h"
#import "BaseEntity.h"
#import "BaseWLService.h"
#import "Common.h"
#import "MTLJSONAdapter.h"
#import "NSData+Godzippa.h"
#import "EGOCache.h"
#import "BaseAPIClient.h"
#import <EGOCache/EGOCache.h>
@implementation BaseWLService
+ (void)saveCacheWithAPIKey:(NSString *)apiKey property:(BaseEntity *)proper data:(id)tweet{
+ (void)saveCacheWithAPIKey:(NSString*)apiKey property:(BaseEntity*)proper data:(id)tweet
{
if (proper.isCache) {
SEL selector = NSSelectorFromString(@"errCode");
IMP imp = [tweet methodForSelector:selector];
NSString* (*func)(id, SEL) = (void *)imp;
NSString *tmpErrCode = func(tweet, selector);
NSString* (*func)(id, SEL) = (void*)imp;
NSString* tmpErrCode = func(tweet, selector);
DLog(@"%@", tmpErrCode);
if (([tmpErrCode isKindOfClass:[NSString class]] && [tmpErrCode isEqualToString:@"0"] ) || ([tmpErrCode isKindOfClass:[NSNumber class]] && [tmpErrCode integerValue]==0)) {
if (([tmpErrCode isKindOfClass:[NSString class]] && [tmpErrCode isEqualToString:@"0"]) || ([tmpErrCode isKindOfClass:[NSNumber class]] && [tmpErrCode integerValue] == 0)) {
[[EGOCache globalCache] setObject:tweet forKey:apiKey];
}
}
}
+ (void)responseFromCacheWithAPIKey:(NSString *)apiKey property:(BaseEntity *)proper completionBlock:(id)subscriber{
+ (void)responseFromCacheWithAPIKey:(NSString*)apiKey property:(BaseEntity*)proper completionBlock:(id)subscriber
{
if (proper.isCache && [[EGOCache globalCache] hasCacheForKey:apiKey]) {
[subscriber sendNext:[[EGOCache globalCache] objectForKey:apiKey]];
[subscriber sendCompleted];
}
}
+(RACSignal*)requireWithProperty:(BaseEntity *)proper
+ (RACSignal*)requireWithProperty:(BaseEntity*)proper
{
// if (proper.requireType == HTTPRequestTypeWithGET) {
// return [self requireWithGetWithProperty:proper];
// }
// return nil;
// if (proper.requireType == HTTPRequestTypeWithGET) {
// return [self requireWithGetWithProperty:proper];
// }
// return nil;
return [self requireWithGetWithProperty:proper];
}
+(RACSignal*)requireWithGetWithProperty:(BaseEntity*)proper
+ (RACSignal*)requireWithGetWithProperty:(BaseEntity*)proper
{
NSString *apiKey = proper.cacheKey;
if (proper.pro && proper.pro[@"page"])
{
apiKey = [apiKey stringByAppendingFormat:@"%@",proper.pro[@"page"]];
NSString* apiKey = proper.cacheKey;
if (proper.pro && proper.pro[@"page"]) {
apiKey = [apiKey stringByAppendingFormat:@"%@", proper.pro[@"page"]];
}
return [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
return [[RACSignal createSignal:^RACDisposable*(id<RACSubscriber> subscriber) {
[[BaseAPIClient sharedClient] GET:[proper reqURL]
parameters: [proper encodePro]
success:^(AFHTTPRequestOperation * __unused task, id json) {
DLog(@"%@", json);
if(json)
{
NSError *error = nil;
id tweet = [MTLJSONAdapter modelOfClass:[proper.responesOBJ class] fromJSONDictionary:json error:&error];
[subscriber sendNext:tweet];
[subscriber sendCompleted];
[self saveCacheWithAPIKey:apiKey property:proper data:tweet];
}
else
{
[subscriber sendNext:nil];
[subscriber sendCompleted];
}
}
failure:^(AFHTTPRequestOperation *__unused task, NSError *error) {
DLog(@"%@", error.description);
[subscriber sendError:error];
[self responseFromCacheWithAPIKey:apiKey property:proper completionBlock:subscriber];
}];
parameters:[proper encodePro]
success:^(AFHTTPRequestOperation* __unused task, id json) {
DLog(@"%@", json);
if (json) {
NSError* error = nil;
id tweet = [MTLJSONAdapter modelOfClass:[proper.responesOBJ class] fromJSONDictionary:json error:&error];
[subscriber sendNext:tweet];
[subscriber sendCompleted];
[self saveCacheWithAPIKey:apiKey property:proper data:tweet];
}
else {
[subscriber sendNext:nil];
[subscriber sendCompleted];
}
}
failure:^(AFHTTPRequestOperation* __unused task, NSError* error) {
DLog(@"%@", error.description);
[subscriber sendError:error];
[self responseFromCacheWithAPIKey:apiKey property:proper completionBlock:subscriber];
}];
return [RACDisposable disposableWithBlock:^{
}];
}] replayLazily];
}] replayLazily];
}
@end
+2
View File
@@ -6,6 +6,8 @@
// Copyright © 2015年 ash. All rights reserved.
//
#import "BaseEntity.h"
#import "BaseWLService.h"
#import "LoginModel.h"
#import "LoginViewModel.h"
@implementation LoginModel
+48 -61
View File
@@ -10,98 +10,86 @@
#import <CommonCrypto/CommonDigest.h>
@implementation NSString (HXAddtions)
+(NSString *) jsonStringWithString:(NSString *) string
+ (NSString*)jsonStringWithString:(NSString*)string
{
return [NSString stringWithFormat:@"\"%@\"",
[[string stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"] stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]
];
[[string stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"] stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]];
}
+(NSString *) jsonStringWithArray:(NSArray *)array
+ (NSString*)jsonStringWithArray:(NSArray*)array
{
NSMutableString *reString = [NSMutableString string];
NSMutableString* reString = [NSMutableString string];
[reString appendString:@"["];
NSMutableArray *values = [NSMutableArray array];
NSMutableArray* values = [NSMutableArray array];
for (id valueObj in array) {
NSString *value = [NSString jsonStringWithObject:valueObj];
NSString* value = [NSString jsonStringWithObject:valueObj];
if (value) {
[values addObject:[NSString stringWithFormat:@"%@",value]];
[values addObject:[NSString stringWithFormat:@"%@", value]];
}
}
[reString appendFormat:@"%@",[values componentsJoinedByString:@","]];
[reString appendString:@"]"];
[reString appendFormat:@"%@", [values componentsJoinedByString:@","]];
[reString appendString:@"]"];
return reString;
}
+(NSString *) jsonStringWithDictionary:(NSDictionary *)dictionary
+ (NSString*)jsonStringWithDictionary:(NSDictionary*)dictionary
{
NSArray *keys = [dictionary allKeys];
NSMutableString *reString = [NSMutableString string];
NSArray* keys = [dictionary allKeys];
NSMutableString* reString = [NSMutableString string];
[reString appendString:@"{"];
NSMutableArray *keyValues = [NSMutableArray array];
for (int i=0; i<[keys count]; i++) {
NSString *name = [keys objectAtIndex:i];
NSMutableArray* keyValues = [NSMutableArray array];
for (int i = 0; i < [keys count]; i++) {
NSString* name = [keys objectAtIndex:i];
id valueObj = [dictionary objectForKey:name];
NSString *value = [NSString jsonStringWithObject:valueObj];
if (value)
{
[keyValues addObject:[NSString stringWithFormat:@"\"%@\":%@",name,value]];
NSString* value = [NSString jsonStringWithObject:valueObj];
if (value) {
[keyValues addObject:[NSString stringWithFormat:@"\"%@\":%@", name, value]];
}
}
[reString appendFormat:@"%@",[keyValues componentsJoinedByString:@","]];
[reString appendFormat:@"%@", [keyValues componentsJoinedByString:@","]];
[reString appendString:@"}"];
return reString;
}
+(NSString *) jsonStringWithObject:(id) object
+ (NSString*)jsonStringWithObject:(id)object
{
NSString *value = nil;
if (!object)
{
NSString* value = nil;
if (!object) {
return value;
}
if ([object isKindOfClass:[NSString class]])
{
if ([object isKindOfClass:[NSString class]]) {
value = [NSString jsonStringWithString:object];
}
else if([object isKindOfClass:[NSDictionary class]])
{
else if ([object isKindOfClass:[NSDictionary class]]) {
value = [NSString jsonStringWithDictionary:object];
}
else if([object isKindOfClass:[NSArray class]])
{
else if ([object isKindOfClass:[NSArray class]]) {
value = [NSString jsonStringWithArray:object];
}
else if([object isKindOfClass:[NSNumber class]])
{
else if ([object isKindOfClass:[NSNumber class]]) {
value = [NSString jsonStringWithString:[object stringValue]];
}
return value;
}
+(NSString *) jsonStringWithRTArray:(NSArray *)array
+ (NSString*)jsonStringWithRTArray:(NSArray*)array
{
NSMutableString *reString = [[NSMutableString alloc] init];
NSMutableString* reString = [[NSMutableString alloc] init];
[reString appendString:@"{"];
NSMutableArray *values = [[NSMutableArray alloc] initWithArray:array];
for (int i=0; i<[values count]; i++)
{
NSString *tempString = [values objectAtIndex:i];
NSString *value = [NSString jsonStringWithString:tempString];
if (i%2 == 0)
{
[reString appendFormat:@"%@:",value];
NSMutableArray* values = [[NSMutableArray alloc] initWithArray:array];
for (int i = 0; i < [values count]; i++) {
NSString* tempString = [values objectAtIndex:i];
NSString* value = [NSString jsonStringWithString:tempString];
if (i % 2 == 0) {
[reString appendFormat:@"%@:", value];
}
else
{
if (i == [values count]-1)
{
[reString appendFormat:@"%@",value];
else {
if (i == [values count] - 1) {
[reString appendFormat:@"%@", value];
}
else
{
[reString appendFormat:@"%@,",value];
else {
[reString appendFormat:@"%@,", value];
}
}
}
@@ -109,17 +97,16 @@
return reString;
}
- (NSString *) md5
- (NSString*)md5
{
const char *cStr = [self UTF8String];
const char* cStr = [self UTF8String];
unsigned char result[16];
CC_MD5( cStr, strlen(cStr), result ); // This is the md5 call
CC_MD5(cStr, (int)strlen(cStr), result); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]];
}
@end
+6 -8
View File
@@ -11,12 +11,10 @@
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
#import <ReactiveCocoa/ReactiveCocoa.h>
#import <Foundation/Foundation.h>
#import <Mantle.h>
#import "Common.h"
#import "BaseEntity.h"
#import "BaseWLService.h"
#import <MBProgressHUD.h>
#import "MBProgressHUD+Util.h"
//#import "Common.h"
//#import "BaseEntity.h"
//#import "BaseWLService.h"
//#import "MBProgressHUD+Util.h"
#import <Mantle/Mantle.h>
#endif /* PrefixHeader_pch */
+2
View File
@@ -7,8 +7,10 @@
//
#import "AWordDefault.h"
#import "Common.h"
#import "LoginViewController.h"
#import "LoginViewModel.h"
#import "MBProgressHUD+Util.h"
@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UIButton* sureBtn;
+5 -4
View File
@@ -6,15 +6,16 @@
// Copyright © 2015年 ash. All rights reserved.
//
#import "BaseViewModel.h"
#import "BaseEntity.h"
#import "BaseModel.h"
#import "BaseViewModel.h"
@implementation BaseViewModel
+(BaseEntity*)requireWithDic:(NSDictionary *)dic withModel:(BaseModel*)model
+ (BaseEntity*)requireWithDic:(NSDictionary*)dic withModel:(BaseModel*)model
{
BaseEntity *pro = [[BaseEntity alloc] init];
BaseEntity* pro = [[BaseEntity alloc] init];
pro.requireType = HTTPRequestTypeWithGET;
pro.responesOBJ = model.class;
pro.responesOBJ = [(id)model class];
pro.reqURL = @"";
pro.pro = dic;
return pro;