├── .DS_Store
├── README.md
└── LJSqlite
├── .DS_Store
├── LJSqlite
├── .DS_Store
├── LJData
│ ├── .DS_Store
│ ├── LJSqlite
│ │ ├── .DS_Store
│ │ ├── LJPath.h
│ │ ├── LJPath.m
│ │ ├── LJSqlite.h
│ │ ├── LJSqliteStatement.h
│ │ ├── NSObject+LJSqlite.h
│ │ ├── LJSqliteMethod.h
│ │ ├── NSObject+LJSqlite.m
│ │ ├── LJSqliteMethod.m
│ │ ├── LJSqliteStatement.m
│ │ └── LJSqlite.m
│ ├── LJSqliteHeader.h
│ └── LJModel
│ │ ├── NSObject+LJModelMethods.h
│ │ ├── LJObjectInformation.h
│ │ ├── LJObjectInformation.m
│ │ └── NSObject+LJModelMethods.m
├── AFNetworking
│ ├── .DS_Store
│ ├── AFNetworking.h
│ ├── AFHTTPRequestOperation.h
│ ├── AFSecurityPolicy.h
│ ├── AFHTTPRequestOperation.m
│ ├── AFNetworkReachabilityManager.h
│ ├── AFNetworkReachabilityManager.m
│ ├── AFSecurityPolicy.m
│ ├── AFHTTPRequestOperationManager.m
│ ├── AFURLResponseSerialization.h
│ ├── AFHTTPSessionManager.m
│ ├── AFHTTPSessionManager.h
│ └── AFURLConnectionOperation.h
├── LJModel.m
├── ViewController.h
├── AppDelegate.h
├── main.m
├── LJModel.h
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── LJHttpRequestManager.h
├── Info.plist
├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.storyboard
├── AppDelegate.m
├── LJHttpRequestManager.m
└── ViewController.m
├── LJSqlite.xcodeproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── songlijun.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcuserdata
│ └── songlijun.xcuserdatad
│ ├── xcschemes
│ ├── xcschememanagement.plist
│ └── LJSqlite.xcscheme
│ └── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
├── LJSqliteTests
├── Info.plist
└── LJSqliteTests.m
└── LJSqliteUITests
├── Info.plist
└── LJSqliteUITests.m
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LJMagicCoder/LJDataModel/HEAD/.DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### LJDataModel
2 | 这是一个model方法。
3 |
4 | 可以用于简单json与model与sqlite之间调用。
5 |
6 |
--------------------------------------------------------------------------------
/LJSqlite/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LJMagicCoder/LJDataModel/HEAD/LJSqlite/.DS_Store
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LJMagicCoder/LJDataModel/HEAD/LJSqlite/LJSqlite/.DS_Store
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LJMagicCoder/LJDataModel/HEAD/LJSqlite/LJSqlite/LJData/.DS_Store
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LJMagicCoder/LJDataModel/HEAD/LJSqlite/LJSqlite/AFNetworking/.DS_Store
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LJMagicCoder/LJDataModel/HEAD/LJSqlite/LJSqlite/LJData/LJSqlite/.DS_Store
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJModel.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/4/1.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "LJModel.h"
10 |
11 | @implementation LJModel
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite.xcodeproj/project.xcworkspace/xcuserdata/songlijun.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LJMagicCoder/LJDataModel/HEAD/LJSqlite/LJSqlite.xcodeproj/project.xcworkspace/xcuserdata/songlijun.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/LJPath.h:
--------------------------------------------------------------------------------
1 | //
2 | // LJPath.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface LJPath : NSObject
12 |
13 | @property (nonatomic,strong) NSString* dbPath;
14 |
15 | + (instancetype)sharedManagerWithPath:(NSString *)dbPath;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqliteHeader.h:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqliteHeader.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/30.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #ifndef LJSqliteHeader_h
10 | #define LJSqliteHeader_h
11 |
12 | #import "NSObject+LJSqlite.h"
13 | #import "NSObject+LJModelMethods.h"
14 | #import "LJSqliteMethod.h"
15 |
16 | #endif /* LJSqliteHeader_h */
17 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // LJModel.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/4/1.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface LJModel : NSObject
12 |
13 | @property (nonatomic ,strong) NSString *id;
14 |
15 | @property (nonatomic ,strong) NSString *fid;
16 |
17 | @property (nonatomic ,strong) NSString *name;
18 |
19 | @property (nonatomic ,strong) NSString *price;
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/LJPath.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJPath.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "LJPath.h"
10 |
11 | @implementation LJPath
12 |
13 | + (instancetype)sharedManagerWithPath:(NSString *)dbPath
14 | {
15 | static LJPath *sharedInstance = nil;
16 | static dispatch_once_t onceToken;
17 | dispatch_once(&onceToken, ^{
18 | sharedInstance = [[LJPath alloc] init];
19 | });
20 | if (dbPath) {
21 | sharedInstance.dbPath = dbPath;
22 | }
23 | return sharedInstance;
24 | }
25 |
26 | @end
27 |
28 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJHttpRequestManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // LJHttpRequestManager.h
3 | // wordNewClasses
4 | //
5 | // Created by 宋立军 on 16/1/28.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class LJHttpRequestManager;
12 |
13 | typedef void (^httpRequsetBlock)(LJHttpRequestManager *manager);
14 |
15 | @interface LJHttpRequestManager : NSObject
16 |
17 | @property (nonatomic,strong) NSDictionary *data;
18 | @property (nonatomic,strong) NSString *error;
19 | @property (nonatomic,strong) NSData *getData;
20 |
21 | //post请求
22 | -(id)initPostWithUrlString:(NSString *)url parameters:(NSDictionary *)dic andBlock:(httpRequsetBlock)block;
23 |
24 | //Get请求
25 | -(id)initGetWithUrlString:(NSString *)url parameters:(NSDictionary *)dic andBlock:(httpRequsetBlock)block;
26 |
27 | @end
28 |
29 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqliteTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqliteUITests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite.xcodeproj/xcuserdata/songlijun.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | LJSqlite.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | ABF5FA781CA3908C007FFED1
16 |
17 | primary
18 |
19 |
20 | ABF5FA911CA3908C007FFED1
21 |
22 | primary
23 |
24 |
25 | ABF5FA9C1CA3908C007FFED1
26 |
27 | primary
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite.xcodeproj/xcuserdata/songlijun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/LJSqlite.h:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqlite.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/30.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef void(^success)(NSArray* result);
12 |
13 | typedef void(^fail)(NSError* error);
14 |
15 | typedef NS_ENUM(NSInteger,LJSqliteType) {
16 | LJSqliteTypeWrite,
17 | LJSqliteTypeRead
18 | };
19 |
20 | @interface LJSqlite : NSObject
21 |
22 | @property (nonatomic,strong) NSString* sqlPath;
23 |
24 | @property (nonatomic,strong) NSDateFormatter* dateFormatter;
25 |
26 | @property (nonatomic,assign) BOOL isSync;
27 |
28 | - (instancetype)initWithPath:(NSString*)dbPath;
29 |
30 | + (instancetype)sqliteWithPath:(NSString*)dbPath;
31 |
32 | - (void)executeSQLWithSqlstringFromModel:(NSString*)sqlString object:(id)modelOrDict executeType:(LJSqliteType)type success:(success)successBlock fail:(fail)failBlock;
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/LJSqliteStatement.h:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqliteStatement.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/31.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "LJSqliteMethod.h"
11 |
12 | @interface LJSqliteStatement : NSObject
13 |
14 | NSString* createTableString(Class modelClass);
15 |
16 | NSString* addColum(id model,NSString *name);
17 |
18 | NSString* insertString(id model);
19 |
20 | NSString* insertStringWithDic(id model ,NSDictionary* dic);
21 |
22 | NSString* deleteString(Class modelClass,NSDictionary* preDict,BOOL isOr);
23 |
24 | NSString* selectString(Class modelClass,NSDictionary* preDict,NSString *sortStr,BOOL isOr);
25 |
26 | NSString* changeString(Class modelClass,NSDictionary* changeDict,NSDictionary* preDict,BOOL isOr);
27 |
28 | NSString* freedomString(Class modelClass,NSString* predicateString,NSString* changeString,LJStatement freedomStatement);
29 |
30 | @end
31 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqliteTests/LJSqliteTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqliteTests.m
3 | // LJSqliteTests
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface LJSqliteTests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation LJSqliteTests
16 |
17 | - (void)setUp {
18 | [super setUp];
19 | // Put setup code here. This method is called before the invocation of each test method in the class.
20 | }
21 |
22 | - (void)tearDown {
23 | // Put teardown code here. This method is called after the invocation of each test method in the class.
24 | [super tearDown];
25 | }
26 |
27 | - (void)testExample {
28 | // This is an example of a functional test case.
29 | // Use XCTAssert and related functions to verify your tests produce the correct results.
30 | }
31 |
32 | - (void)testPerformanceExample {
33 | // This is an example of a performance test case.
34 | [self measureBlock:^{
35 | // Put the code you want to measure the time of here.
36 | }];
37 | }
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/NSObject+LJSqlite.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSObject+LJSqlite.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/31.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef void(^success)(NSArray* result);
12 |
13 | typedef void(^fail)(NSError* error);
14 |
15 | @class LJSqliteMethod;
16 |
17 | @interface NSObject (LJSqlite)
18 |
19 | /********************************-必要操作-********************************/
20 |
21 | /*!
22 | @brief 创建表
23 | */
24 | + (void)lj_createTable;
25 |
26 | /*!
27 | @brief 数据库操作(阻塞)
28 | */
29 | + (NSArray *)lj_syncSqliteMethod:(LJSqliteMethod *)method fail:(fail)errorBlock;
30 |
31 | /*!
32 | @brief 数据库操作(非阻塞)
33 | */
34 | + (void)lj_asyncSqliteMethod:(LJSqliteMethod *)method success:(success)successBlock fail:(fail)errorBlock;
35 |
36 |
37 | /********************************-非必要操作-********************************/
38 |
39 | /*!
40 | @brief 指定数据库(不调用为默认数据库路径)
41 | */
42 | + (void)lj_dbName:(NSString *)dbName;
43 |
44 | /*!
45 | @brief 对数据库增加字段(modle里需先添加上)
46 | */
47 | + (void)addColum:(NSString*)name;
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJModel/NSObject+LJModelMethods.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSObject+LJModelMethods.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSObject (LJModelMethods)
12 |
13 | /********************************-object转成model-********************************/
14 | /*!
15 | @brief 将数组中的Dictionary或Json转成Model,以数组形式传回
16 | */
17 | + (NSArray *)lj_ModelArrayFromDictOrJsonArray:(NSArray*)array;
18 |
19 | /*!
20 | @brief 将Dictionary或Json转成Model
21 | */
22 | + (id)lj_ModelFromDictionaryOrJson:(id)dicOrJson;
23 |
24 | /********************************-model转成object-********************************/
25 | /*!
26 | @brief 将数组中的Model转成Dictionary(如果是string或data类型会转成json),以数组形式传回
27 | */
28 | - (NSArray *)lj_DictOrJsonArrayFromModelArray;
29 |
30 | /*!
31 | @brief 将Model转成NSDictionary
32 | */
33 | - (NSDictionary *)lj_DictionaryFromModel;
34 |
35 | /*!
36 | @brief 将Model转成Json
37 | */
38 | - (NSData *)lj_JsonFromModel;
39 |
40 | /********************************--********************************/
41 |
42 | - (NSDictionary*)lj_ModelToDictionary;
43 |
44 | + (NSDictionary*)getAllPropertyNameAndType;
45 |
46 | + (NSDictionary*)determineProperties;
47 |
48 | + (NSString*)getTypeNameWith:(NSString*)propertyName;
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqliteUITests/LJSqliteUITests.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqliteUITests.m
3 | // LJSqliteUITests
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface LJSqliteUITests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation LJSqliteUITests
16 |
17 | - (void)setUp {
18 | [super setUp];
19 |
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 |
22 | // In UI tests it is usually best to stop immediately when a failure occurs.
23 | self.continueAfterFailure = NO;
24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
25 | [[[XCUIApplication alloc] init] launch];
26 |
27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
28 | }
29 |
30 | - (void)tearDown {
31 | // Put teardown code here. This method is called after the invocation of each test method in the class.
32 | [super tearDown];
33 | }
34 |
35 | - (void)testExample {
36 | // Use recording to get started writing UI tests.
37 | // Use XCTAssert and related functions to verify your tests produce the correct results.
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSAppTransportSecurity
6 |
7 | NSAllowsArbitraryLoads
8 |
9 |
10 | CFBundleDevelopmentRegion
11 | en
12 | CFBundleExecutable
13 | $(EXECUTABLE_NAME)
14 | CFBundleIdentifier
15 | $(PRODUCT_BUNDLE_IDENTIFIER)
16 | CFBundleInfoDictionaryVersion
17 | 6.0
18 | CFBundleName
19 | $(PRODUCT_NAME)
20 | CFBundlePackageType
21 | APPL
22 | CFBundleShortVersionString
23 | 1.0
24 | CFBundleSignature
25 | ????
26 | CFBundleVersion
27 | 1
28 | LSRequiresIPhoneOS
29 |
30 | UILaunchStoryboardName
31 | LaunchScreen
32 | UIMainStoryboardFile
33 | Main
34 | UIRequiredDeviceCapabilities
35 |
36 | armv7
37 |
38 | UISupportedInterfaceOrientations
39 |
40 | UIInterfaceOrientationPortrait
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJModel/LJObjectInformation.h:
--------------------------------------------------------------------------------
1 | //
2 | // LJObjectInformation.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | typedef NS_ENUM(NSUInteger,LJBaseTypeEcoding) {
13 | LJBaseTypeEcodingUnknow,
14 | LJBaseTypeEcodingINT,
15 | LJBaseTypeEcodingLONG,
16 | LJBaseTypeEcodingULONG,
17 | LJBaseTypeEcodingCHAR,
18 | LJBaseTypeEcodingFLOAT,
19 | LJBaseTypeEcodingBOOL,
20 | LJBaseTypeEcodingDOUBLE
21 | };
22 |
23 | typedef NS_ENUM(NSUInteger,LJNSTypeEcoding) {
24 | LJNSTypeUNknow,
25 | LJNSTypeNSString,
26 | LJNSTypeNSNumber,
27 | LJNSTypeNSDate,
28 | LJNSTypeNSData,
29 | LJNSTypeNSURL,
30 | LJNSTypeNSArray,
31 | LJNSTypeNSDictionary,
32 | LJNSTypeUIImage
33 | };
34 |
35 | //model内的元素的信息
36 | @interface LJObjectInformation : NSObject
37 |
38 | @property (nonatomic) Class cls;
39 |
40 | @property (nonatomic) objc_property_t property_t;
41 |
42 | @property (nonatomic,copy) NSString* name;
43 |
44 | @property (nonatomic,assign) LJBaseTypeEcoding baseTypeEcoding;
45 |
46 | @property (nonatomic,assign) LJNSTypeEcoding nsTypeEcoding;
47 |
48 | @property (nonatomic) SEL set;
49 |
50 | @property (nonatomic) SEL get;
51 |
52 | @property (nonatomic,copy) NSString* type;
53 |
54 | - (instancetype)initWithProperty:(objc_property_t)property;
55 |
56 | @end
57 |
58 | //model类信息
59 | @interface LJClassInformation : NSObject
60 |
61 | @property (nonatomic)Class cls;
62 |
63 | @property (nonatomic)Class superClass;
64 |
65 | @property (nonatomic)Class metaClass;
66 |
67 | @property (nonatomic,assign) BOOL isMetaClass;
68 |
69 | @property (nonatomic,strong) NSMutableDictionary* objectInfoDic;
70 |
71 | - (instancetype)initWithClass:(Class)cls;
72 |
73 | - (LJObjectInformation*)objectInfoWithName:(NSString*)name;
74 |
75 | @end
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFNetworking.h:
--------------------------------------------------------------------------------
1 | // AFNetworking.h
2 | //
3 | // Copyright (c) 2013 AFNetworking (http://afnetworking.com/)
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #import
24 | #import
25 |
26 | #ifndef _AFNETWORKING_
27 | #define _AFNETWORKING_
28 |
29 | #import "AFURLRequestSerialization.h"
30 | #import "AFURLResponseSerialization.h"
31 | #import "AFSecurityPolicy.h"
32 | #import "AFNetworkReachabilityManager.h"
33 |
34 | #import "AFURLConnectionOperation.h"
35 | #import "AFHTTPRequestOperation.h"
36 | #import "AFHTTPRequestOperationManager.h"
37 |
38 | #if ( ( defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) || \
39 | ( defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 ) )
40 | #import "AFURLSessionManager.h"
41 | #import "AFHTTPSessionManager.h"
42 | #endif
43 |
44 | #endif /* _AFNETWORKING_ */
45 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/LJSqliteMethod.h:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqliteMethod.h
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/4/1.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "LJSqlite.h"
11 |
12 | typedef NS_ENUM(NSInteger,LJStatement){
13 | LJAddStatement,
14 | LJDeleteStatement,
15 | LJQueryStatement,
16 | LJChangeStatement,
17 | LJFreedomStatement
18 | };
19 |
20 | @class LJSqliteMethodElement;
21 |
22 | @interface LJSqliteMethod : NSObject
23 |
24 | /********************************-调用以下方法操作数据库-********************************/
25 |
26 | @property(nonatomic ,assign)BOOL isOr; //以下方条件默认为and衔接 isOr设为YES后条件为or衔接
27 |
28 | /*!
29 | @brief 增
30 | @result LJSqliteMethod实例
31 | @param dataArrayOrModel(字典数组/model数组/字典/model) 要增加的数据
32 | */
33 | + (LJSqliteMethod *)addDataToDBFromArray:(id)dataArrayOrModel;
34 |
35 | /*!
36 | @brief 删
37 | @result LJSqliteMethod实例
38 | @param deleteDict(key为字段,value为条件)(传nil为全删)
39 | */
40 | + (LJSqliteMethod *)deleteDataToDBFromDict:(NSDictionary *)deleteDict;
41 |
42 | /*!
43 | @brief 查
44 | @result LJSqliteMethod实例
45 | @param queryDict(key为字段,value为条件)(传nil为全查)
46 | */
47 | + (LJSqliteMethod *)selectDataToDBFromDict:(NSDictionary *)queryDict;
48 | //排序(查)(不调用此方法为默认排序)
49 | - (void)sortisNormalConditions:(NSString *)condStr Sort:(BOOL)normalSort;
50 |
51 | /*!
52 | @brief 改
53 | @result LJSqliteMethod实例
54 | @param changeDict(要改变的字段)(key为字段,value为条件)(为空无效)
55 | statementDict(条件)(key为字段,value为条件)(传nil为所有区域)
56 | */
57 | + (LJSqliteMethod *)upDataToDBFromArray:(NSDictionary *)changeDict statementDict:(NSDictionary *)statementDict;
58 |
59 |
60 |
61 | /********************************-自定义谓词操作数据库-********************************/
62 |
63 | /*!
64 | @brief 删(谓语补全) (例子:id = 5 and name = 'abc' or age = 20)
65 | */
66 | + (LJSqliteMethod *)deleteDataToFreedomString:(NSString *)freedomString;
67 |
68 | /*!
69 | @brief 查(谓语补全) (例子:id = 5 and name = 'abc' or age = 20)
70 | */
71 | + (LJSqliteMethod *)selectDataToFreedomString:(NSString *)freedomString;
72 |
73 | /*!
74 | @brief 改(谓语补全) (例子:changeStr:id = 5 set name = 'abc' condString:id = 6 and name = 'cba' or age = 21)
75 | */
76 | + (LJSqliteMethod *)upDataToChangeStr:(NSString *)changeStr condString:(NSString *)condString;
77 |
78 |
79 |
80 | /********************************--********************************/
81 |
82 | @property(nonatomic ,strong)NSArray *dataArray;
83 |
84 | @property(nonatomic ,strong)NSString *sqlString;
85 |
86 | @property(nonatomic ,assign)LJSqliteType type;
87 |
88 | @property(nonatomic ,assign)LJStatement statement;
89 |
90 | @property(nonatomic ,strong)NSDictionary *statementDict;
91 |
92 | @property(nonatomic ,strong)NSDictionary *changeDict;
93 |
94 | @property(nonatomic ,strong)NSString *sortStr;
95 |
96 | @property(nonatomic ,assign)LJStatement freedomStatement;
97 |
98 | @property(nonatomic ,strong)NSString *freedomStr;
99 |
100 | @property(nonatomic ,strong)NSString *changeStr;
101 |
102 | - (NSString *)joiningTogetherStatement:(id)idClass;
103 |
104 | @end
105 |
106 |
107 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJHttpRequestManager.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJHttpRequestManager.m
3 | // wordNewClasses
4 | //
5 | // Created by 宋立军 on 16/1/28.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "LJHttpRequestManager.h"
10 | #import "AFNetworking.h"
11 |
12 | @interface LJHttpRequestManager()
13 |
14 | @property (nonatomic,strong) AFHTTPRequestOperationManager *manager;
15 | @end
16 |
17 | @implementation LJHttpRequestManager
18 |
19 |
20 | //post请求
21 | -(id)initPostWithUrlString:(NSString *)url parameters:(NSDictionary *)dic andBlock:(httpRequsetBlock)block{
22 | if (self = [super init]) {
23 | [self requestPostDataWithString:url parameters:dic andBlock:block];
24 | }
25 | return self;
26 | }
27 |
28 | -(void)requestPostDataWithString:(NSString *)url parameters:(NSDictionary *)dic andBlock:(httpRequsetBlock)tempBlock{
29 |
30 | _manager = [AFHTTPRequestOperationManager manager];
31 |
32 | //申明返回的结果是json类型
33 | _manager.responseSerializer = [AFJSONResponseSerializer serializer];
34 |
35 | //申明请求的数据是json类型
36 | // _manager.requestSerializer=[AFJSONRequestSerializer serializer];
37 |
38 | //如果报接受类型不一致请替换一致text/html或别的
39 | _manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/x-json",@"text/html",nil];
40 |
41 | [_manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
42 | //解析
43 | self.data = responseObject;
44 | self.error = @"";
45 | tempBlock(self);
46 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
47 | self.error = error.localizedDescription;
48 |
49 | tempBlock(self);
50 | }];
51 | }
52 |
53 | //get请求
54 | -(id)initGetWithUrlString:(NSString *)url parameters:(NSDictionary *)dic andBlock:(httpRequsetBlock)block{
55 | if (self = [super init]) {
56 | [self requestDataWithString:url parameters:dic andBlock:block];
57 | }
58 | return self;
59 | }
60 | -(void)requestDataWithString:(NSString *)url parameters:(NSDictionary *)dic andBlock:(httpRequsetBlock)tempBlock{
61 | _manager = [AFHTTPRequestOperationManager manager];
62 | _manager.responseSerializer = [AFHTTPResponseSerializer serializer];
63 |
64 | NSArray *key = [dic allKeys];
65 | NSArray *value = [dic allValues];
66 |
67 | NSMutableString *string = [NSMutableString string];
68 | for (int i = 0; i < dic.count; i++) {
69 | [string appendString:[NSString stringWithFormat:@"/%@/%@",key[i],value[i]]];
70 | }
71 |
72 | NSString *finalUrl;
73 | if (dic.count > 0) {
74 | finalUrl = [NSString stringWithFormat:@"%@%@",url,[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
75 | }else{
76 | finalUrl = url;
77 | }
78 |
79 | [_manager GET:finalUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
80 |
81 | //解析
82 | self.getData = responseObject;
83 | self.error = @"";
84 | tempBlock(self);
85 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
86 | self.error = error.localizedDescription;
87 | tempBlock(self);
88 | }];
89 | }
90 | @end
91 |
92 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/NSObject+LJSqlite.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSObject+LJSqlite.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/31.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #define run_in_queue(...) dispatch_async([self executeQueue], ^{\
10 | __VA_ARGS__; \
11 | })
12 |
13 | #define DatabasePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]stringByAppendingPathComponent:@"data.sqlite"];
14 |
15 | #import "NSObject+LJSqlite.h"
16 | #import "NSObject+LJModelMethods.h"
17 | #import "LJPath.h"
18 | #import "LJSqlite.h"
19 | #import "LJSqliteStatement.h"
20 | #import "LJSqliteMethod.h"
21 | #import
22 |
23 | @implementation NSObject (LJSqlite)
24 |
25 | - (dispatch_queue_t)executeQueue
26 | {
27 | static dispatch_queue_t executeQueue;
28 | static dispatch_once_t onceToken;
29 | dispatch_once(&onceToken, ^{
30 | executeQueue = dispatch_queue_create("com.sancai.ljdb", DISPATCH_QUEUE_SERIAL);
31 | });
32 | return executeQueue;
33 | }
34 |
35 | + (dispatch_queue_t)executeQueue
36 | {
37 | return [[self new] executeQueue];
38 | }
39 |
40 | + (void)lj_dbName:(NSString *)dbName
41 | {
42 | if (dbName.length) {
43 | NSString *dbNewPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.sqlite",dbName]];
44 | [LJPath sharedManagerWithPath:dbNewPath];
45 | }
46 | }
47 |
48 | + (void)addColum:(NSString*)name
49 | {
50 | LJSqlite* sqlite = [LJSqlite sqliteWithPath:[self dbPath]];
51 | [sqlite executeSQLWithSqlstringFromModel:addColum(self, name) object:nil executeType:LJSqliteTypeWrite success:nil fail:nil];
52 | }
53 |
54 |
55 | + (NSString*)dbPath
56 | {
57 | if ([LJPath sharedManagerWithPath:nil].dbPath.length == 0) {
58 | return DatabasePath;
59 | }else
60 | return [LJPath sharedManagerWithPath:nil].dbPath;
61 | }
62 |
63 | + (void)lj_createTable
64 | {
65 | LJSqlite* sqlite = [LJSqlite sqliteWithPath:[self dbPath]];
66 | [sqlite executeSQLWithSqlstringFromModel:createTableString(self) object:nil executeType:LJSqliteTypeWrite success:nil fail:nil];
67 | }
68 |
69 | + (NSArray *)lj_syncSqliteMethod:(LJSqliteMethod *)method fail:(fail)errorBlock
70 | {
71 | __block NSMutableArray* array = [NSMutableArray array];
72 | [self lj_sqliteMethod:method success:^(NSArray *result) {
73 | for (NSDictionary* dic in result) {
74 | [array addObject:[self lj_ModelFromDictionaryOrJson:dic]];
75 | }
76 | } fail:errorBlock isSync:YES];
77 | return array;
78 | }
79 |
80 | + (void)lj_asyncSqliteMethod:(LJSqliteMethod *)method success:(success)successBlock fail:(fail)errorBlock
81 | {
82 | run_in_queue([self lj_sqliteMethod:method success:successBlock fail:errorBlock isSync:NO]);
83 | }
84 |
85 | + (void)lj_sqliteMethod:(LJSqliteMethod *)method success:(success)successBlock fail:(fail)errorBlock isSync:(BOOL)isSync
86 | {
87 | LJSqlite* sqlite = [LJSqlite sqliteWithPath:[self dbPath]];
88 | sqlite.isSync = isSync;
89 | if (method.dataArray.count) {
90 | for (id data in method.dataArray) {
91 | if ([data isKindOfClass:[NSDictionary class]]) {
92 | [sqlite executeSQLWithSqlstringFromModel:insertStringWithDic(self, data) object:data executeType:method.type success:nil fail:errorBlock];
93 | }else
94 | [sqlite executeSQLWithSqlstringFromModel:[method joiningTogetherStatement:self] object:data executeType:method.type success:nil fail:errorBlock];
95 | }
96 | }else
97 | [sqlite executeSQLWithSqlstringFromModel:[method joiningTogetherStatement:self] object:nil executeType:method.type success:successBlock fail:errorBlock];
98 | }
99 |
100 | @end
101 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/LJSqliteMethod.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqliteMethod.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/4/1.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "LJSqliteMethod.h"
10 | #import "LJSqliteStatement.h"
11 |
12 | @implementation LJSqliteMethod
13 |
14 | - (NSString *)joiningTogetherStatement:(id)idClass
15 | {
16 | switch (self.statement) {
17 | case LJAddStatement:
18 | return insertString(idClass);
19 | case LJDeleteStatement:
20 | return deleteString(idClass, self.statementDict, self.isOr);
21 | case LJQueryStatement:
22 | return selectString(idClass, self.statementDict,self.sortStr, self.isOr);
23 | case LJChangeStatement:
24 | return changeString(idClass, self.changeDict, self.statementDict, self.isOr);
25 | case LJFreedomStatement:
26 | return freedomString(idClass, self.freedomStr, self.changeStr, self.freedomStatement);
27 | default:
28 | return nil;
29 | }
30 | }
31 |
32 | -(instancetype)initWithDataArray:(id)data
33 | {
34 | self = [super init];
35 | if (self) {
36 | if ([data isKindOfClass:[NSArray class]]) {
37 | self.dataArray = data;
38 | }else{
39 | self.dataArray = [NSArray arrayWithObject:data];
40 | }
41 | }
42 | return self;
43 | }
44 |
45 | + (LJSqliteMethod *)addDataToDBFromArray:(id)dataArrayOrModel
46 | {
47 | LJSqliteMethod *method = [[LJSqliteMethod alloc]initWithDataArray:dataArrayOrModel];
48 | method.type = LJSqliteTypeWrite;
49 | method.statement = LJAddStatement;
50 | return method;
51 | }
52 |
53 | + (LJSqliteMethod *)deleteDataToDBFromDict:(NSDictionary *)deleteDict
54 | {
55 | LJSqliteMethod *method = [[LJSqliteMethod alloc]init];
56 | method.statementDict = deleteDict;
57 | method.type = LJSqliteTypeWrite;
58 | method.statement = LJDeleteStatement;
59 | return method;
60 | }
61 |
62 | + (LJSqliteMethod *)selectDataToDBFromDict:(NSDictionary *)queryDict
63 | {
64 | LJSqliteMethod *method = [[LJSqliteMethod alloc]init];
65 | method.statementDict = queryDict;
66 | method.type = LJSqliteTypeRead;
67 | method.statement = LJQueryStatement;
68 | return method;
69 | }
70 |
71 | - (void)sortisNormalConditions:(NSString *)condStr Sort:(BOOL)normalSort
72 | {
73 | if (condStr) {
74 | if (normalSort) {
75 | self.sortStr = [NSString stringWithFormat:@" ORDER BY %@ ASC",condStr];
76 | }else
77 | self.sortStr = [NSString stringWithFormat:@" ORDER BY %@ DESC",condStr];
78 | }
79 | }
80 |
81 | + (LJSqliteMethod *)upDataToDBFromArray:(NSDictionary *)changeDict statementDict:(NSDictionary *)statementDict
82 | {
83 | LJSqliteMethod *method = [[LJSqliteMethod alloc]init];
84 | method.changeDict = changeDict;
85 | method.statementDict = statementDict;
86 | method.type = LJSqliteTypeWrite;
87 | method.statement = LJChangeStatement;
88 | return method;
89 | }
90 |
91 | + (LJSqliteMethod *)deleteDataToFreedomString:(NSString *)freedomString
92 | {
93 | LJSqliteMethod *method = [[LJSqliteMethod alloc]init];
94 | method.type = LJSqliteTypeWrite;
95 | method.statement = LJFreedomStatement;
96 | method.freedomStatement = LJDeleteStatement;
97 | method.freedomStr = freedomString;
98 | return method;
99 | }
100 |
101 | + (LJSqliteMethod *)selectDataToFreedomString:(NSString *)freedomString
102 | {
103 | LJSqliteMethod *method = [[LJSqliteMethod alloc]init];
104 | method.type = LJSqliteTypeRead;
105 | method.statement = LJFreedomStatement;
106 | method.freedomStatement = LJQueryStatement;
107 | method.freedomStr = freedomString;
108 | return method;
109 | }
110 |
111 | + (LJSqliteMethod *)upDataToChangeStr:(NSString *)changeStr condString:(NSString *)condString
112 | {
113 | LJSqliteMethod *method = [[LJSqliteMethod alloc]init];
114 | method.type = LJSqliteTypeWrite;
115 | method.statement = LJFreedomStatement;
116 | method.freedomStatement = LJChangeStatement;
117 | method.changeStr = changeStr;
118 | method.freedomStr = condString;
119 | return method;
120 | }
121 |
122 |
123 | @end
124 |
125 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFHTTPRequestOperation.h:
--------------------------------------------------------------------------------
1 | // AFHTTPRequestOperation.h
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 | #import "AFURLConnectionOperation.h"
24 |
25 | /**
26 | `AFHTTPRequestOperation` is a subclass of `AFURLConnectionOperation` for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request.
27 | */
28 | @interface AFHTTPRequestOperation : AFURLConnectionOperation
29 |
30 | ///------------------------------------------------
31 | /// @name Getting HTTP URL Connection Information
32 | ///------------------------------------------------
33 |
34 | /**
35 | The last HTTP response received by the operation's connection.
36 | */
37 | @property (readonly, nonatomic, strong) NSHTTPURLResponse *response;
38 |
39 | /**
40 | Responses sent from the server in data tasks created with `dataTaskWithRequest:success:failure:` and run using the `GET` / `POST` / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an AFHTTPResponse serializer, which uses the raw data as its response object. The serializer validates the status code to be in the `2XX` range, denoting success. If the response serializer generates an error in `-responseObjectForResponse:data:error:`, the `failure` callback of the session task or request operation will be executed; otherwise, the `success` callback will be executed.
41 |
42 | @warning `responseSerializer` must not be `nil`. Setting a response serializer will clear out any cached value
43 | */
44 | @property (nonatomic, strong) AFHTTPResponseSerializer * responseSerializer;
45 |
46 | /**
47 | An object constructed by the `responseSerializer` from the response and response data. Returns `nil` unless the operation `isFinished`, has a `response`, and has `responseData` with non-zero content length. If an error occurs during serialization, `nil` will be returned, and the `error` property will be populated with the serialization error.
48 | */
49 | @property (readonly, nonatomic, strong) id responseObject;
50 |
51 | ///-----------------------------------------------------------
52 | /// @name Setting Completion Block Success / Failure Callbacks
53 | ///-----------------------------------------------------------
54 |
55 | /**
56 | Sets the `completionBlock` property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If `error` returns a value, which can be caused by an unacceptable status code or content type, then `failure` is executed. Otherwise, `success` is executed.
57 |
58 | This method should be overridden in subclasses in order to specify the response object passed into the success block.
59 |
60 | @param success The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request.
61 | @param failure The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occurred during the request.
62 | */
63 | - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
64 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite.xcodeproj/xcuserdata/songlijun.xcuserdatad/xcschemes/LJSqlite.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
43 |
49 |
50 |
51 |
52 |
53 |
59 |
60 |
61 |
62 |
63 |
64 |
74 |
76 |
82 |
83 |
84 |
85 |
86 |
87 |
93 |
95 |
101 |
102 |
103 |
104 |
106 |
107 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 | #define kPOST_TEST [NSString stringWithFormat:@"http://www.dljgb.cn/phone/index.php"]
9 | #define SCREEN_WIDTH [[UIScreen mainScreen]bounds].size.width //屏幕宽度
10 | #define SCREEN_HEIGHTH [[UIScreen mainScreen]bounds].size.height //屏幕高度
11 |
12 | #import "ViewController.h"
13 | #import "LJHttpRequestManager.h"
14 | #import "LJSqliteHeader.h"
15 | #import "LJModel.h"
16 |
17 | @interface ViewController ()
18 |
19 | @end
20 |
21 | @implementation ViewController
22 |
23 | - (void)viewDidLoad {
24 | [super viewDidLoad];
25 | [self loadUI];
26 | [self loadData];
27 | }
28 |
29 | - (void)loadUI
30 | {
31 | UIButton *addBtn = [self loadBtn:1 name:@"增"];
32 | [addBtn addTarget:self action:@selector(addBtnMethod) forControlEvents:UIControlEventTouchUpInside];
33 |
34 | UIButton *deleteBtn = [self loadBtn:2 name:@"删"];
35 | [deleteBtn addTarget:self action:@selector(deleteBtnMethod) forControlEvents:UIControlEventTouchUpInside];
36 |
37 | UIButton *selectedBtn = [self loadBtn:3 name:@"查"];
38 | [selectedBtn addTarget:self action:@selector(selectedBtnMethod) forControlEvents:UIControlEventTouchUpInside];
39 |
40 | UIButton *upDataBtn = [self loadBtn:4 name:@"改"];
41 | [upDataBtn addTarget:self action:@selector(upDataBtnMethod) forControlEvents:UIControlEventTouchUpInside];
42 |
43 | }
44 |
45 | - (UIButton *)loadBtn:(int)num name:(NSString *)name
46 | {
47 | UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH *0.8, 40)];
48 | btn.center = CGPointMake(SCREEN_WIDTH *0.5, SCREEN_HEIGHTH *0.2 *num);
49 | btn.backgroundColor = [UIColor orangeColor];
50 | [btn setTitle:name forState:UIControlStateNormal];
51 | btn.layer.cornerRadius = 5;
52 | [self.view addSubview:btn];
53 | return btn;
54 | }
55 | - (void)loadData
56 | {
57 | // [LJModel lj_dbName:@"LJDBName"];
58 | [LJModel lj_createTable];
59 | }
60 |
61 | - (void)addBtnMethod
62 | {
63 | NSArray *array = [self falseData];
64 | [LJModel lj_syncSqliteMethod:[LJSqliteMethod addDataToDBFromArray:array] fail:nil];
65 | }
66 |
67 | - (void)deleteBtnMethod
68 | {
69 | [LJModel lj_syncSqliteMethod:[LJSqliteMethod deleteDataToDBFromDict:nil] fail:nil];
70 | }
71 |
72 | - (void)selectedBtnMethod
73 | {
74 | // LJSqliteMethod *ljMethod = [LJSqliteMethod selectDataToDBFromDict:nil];//@{@"id":@"5",@"fid":@"1007"}
75 | LJSqliteMethod *ljMethod = [LJSqliteMethod selectDataToFreedomString:nil];//@"id = '5' or fid = '1019'"
76 | ljMethod.isOr = YES;
77 | NSArray *dataArray = [LJModel lj_syncSqliteMethod:ljMethod fail:^(NSError *error) {
78 | NSLog(@"queryError...%@",error);
79 | }];
80 | NSLog(@"queryDataModle%@",dataArray);
81 |
82 | // //异步加载
83 | // [LJModel lj_asyncSqliteMethod:ljMethod success:^(NSArray *result) {
84 | // NSLog(@"queryData%@",result);
85 | // NSArray *dataArray = [LJModel lj_ModelArrayFromDictOrJsonArray:result];
86 | // NSLog(@"queryDataModle%@",dataArray);
87 | // } fail:^(NSError *error) {
88 | // NSLog(@"queryError...%@",error);
89 | // }];
90 | }
91 |
92 | - (void)upDataBtnMethod
93 | {
94 | [LJModel lj_syncSqliteMethod:[LJSqliteMethod upDataToDBFromArray:@{@"id":@"666",@"fid":@"123a"} statementDict:@{@"id":@"15"}] fail:nil];
95 | // [LJModel lj_syncSqliteMethod:[LJSqliteMethod upDataToChangeStr:@"id = 'a' , fid = 'b'" condString:@"id = '9'"] fail:nil];
96 | }
97 |
98 | #pragma mark 数据测试
99 | - (NSArray *)falseData
100 | {
101 | NSMutableDictionary *dict = [NSMutableDictionary dictionary];
102 | NSMutableArray *array = [NSMutableArray array];
103 | for (int i = 0; i<100; i++) {
104 | [dict removeAllObjects];
105 | [dict setObject:[NSString stringWithFormat:@"%d",i] forKey:[NSString stringWithFormat:@"id"]];
106 | [dict setObject:[NSString stringWithFormat:@"%d",i + 1000] forKey:[NSString stringWithFormat:@"fid"]];
107 | [dict setObject:[NSString stringWithFormat:@"%d",i + 2000] forKey:[NSString stringWithFormat:@"name"]];
108 | [dict setObject:[NSString stringWithFormat:@"%d",i + 3000] forKey:[NSString stringWithFormat:@"price"]];
109 | [array addObject:[dict copy]];
110 | }
111 | return array;
112 | }
113 |
114 | -(void)downloadData:(void(^)(NSArray *array))Success
115 | {
116 | LJHttpRequestManager *manager = [[LJHttpRequestManager alloc] initPostWithUrlString:kPOST_TEST parameters:nil andBlock:^(LJHttpRequestManager *manager) {
117 | @try {
118 |
119 | //判断网络请求是否成功
120 | if (![manager.error isEqualToString:@""])NSLog(@"返回错误!");
121 |
122 | Success(manager.data[@"classify"]);
123 | }
124 | @catch (NSException *exception) {
125 |
126 | }
127 | @finally {
128 |
129 | }
130 | }];
131 | NSLog(@"%@",manager);
132 | }
133 |
134 |
135 | @end
136 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJModel/LJObjectInformation.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJObjectInformation.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "LJObjectInformation.h"
10 |
11 | @implementation LJObjectInformation
12 |
13 | - (instancetype)initWithProperty:(objc_property_t)property
14 | {
15 | self = [super init];
16 | if (self) {
17 | _property_t = property;
18 | _name = [NSString stringWithUTF8String:property_getName(property)];
19 | unsigned int count;
20 | objc_property_attribute_t *t = property_copyAttributeList(property, &count);
21 | objc_property_attribute_t p = t[0];
22 | size_t len = strlen(p.value);
23 | if (len > 3) {
24 | char name[len - 2];
25 | name[len - 3] = '\0';
26 | memcpy(name, p.value + 2, len - 3);
27 | _cls = objc_getClass(name);
28 | _type = [NSString stringWithUTF8String:name];
29 | _nsTypeEcoding = nsTypeEcoding(_type);
30 | }else {
31 | _type = [NSString stringWithUTF8String:p.value];
32 | if (_type.length>1) {
33 | _type = [_type substringToIndex:1];
34 | }
35 | if (_type.length>0) {
36 | _baseTypeEcoding = baseTypeEcoding([_type characterAtIndex:0]);
37 | }
38 | }
39 | free(t);
40 | if (_name.length>0) {
41 | _set = NSSelectorFromString([NSString stringWithFormat:@"set%@%@:",[[_name substringToIndex:1] uppercaseString],[_name substringFromIndex:1]]);
42 | _get = NSSelectorFromString(_name);
43 | }
44 | }
45 | return self;
46 | }
47 |
48 | static LJNSTypeEcoding nsTypeEcoding(NSString *type)
49 | {
50 | if ([type isEqualToString:@"NSString"]) {
51 | return LJNSTypeNSString;
52 | }
53 | if ([type isEqualToString:@"NSNumber"]) {
54 | return LJNSTypeNSNumber;
55 | }
56 | if ([type isEqualToString:@"NSDate"]) {
57 | return LJNSTypeNSDate;
58 | }
59 | if ([type isEqualToString:@"NSData"]) {
60 | return LJNSTypeNSData;
61 | }
62 | if ([type isEqualToString:@"NSURL"]) {
63 | return LJNSTypeNSURL;
64 | }
65 | if ([type isEqualToString:@"NSArray"]) {
66 | return LJNSTypeNSArray;
67 | }
68 | if ([type isEqualToString:@"NSDictionary"]) {
69 | return LJNSTypeNSDictionary;
70 | }
71 | if ([type isEqualToString:@"UIImage"]) {
72 | return LJNSTypeUIImage;
73 | }
74 | return LJNSTypeUNknow;
75 | }
76 |
77 | static LJBaseTypeEcoding baseTypeEcoding(char type)
78 | {
79 | switch (type) {
80 | case 'Q':
81 | return LJBaseTypeEcodingULONG;
82 | case 'i':
83 | return LJBaseTypeEcodingINT;
84 | case 'q':
85 | return LJBaseTypeEcodingLONG;
86 | case 'f':
87 | return LJBaseTypeEcodingFLOAT;
88 | case 'd':
89 | return LJBaseTypeEcodingDOUBLE;
90 | case 'B':
91 | return LJBaseTypeEcodingBOOL;
92 | case 'b':
93 | return LJBaseTypeEcodingBOOL;
94 | case 'c':
95 | return LJBaseTypeEcodingCHAR;
96 | default:
97 | return LJBaseTypeEcodingUnknow;
98 | }
99 | }
100 |
101 | @end
102 |
103 |
104 | static NSMutableDictionary* objectInfoCacheDic;
105 |
106 | @implementation LJClassInformation
107 |
108 | -(NSMutableDictionary *)objectInfoDic
109 | {
110 | if (!_objectInfoDic) {
111 | _objectInfoDic = [NSMutableDictionary dictionary];
112 | }
113 | return _objectInfoDic;
114 | }
115 |
116 | - (instancetype)initWithClass:(Class)cls{
117 |
118 | if ([self isCacheWithClass:cls]) {
119 | return [self classInfoWithClass:cls];
120 | }
121 | self = [super init];
122 | if (self) {
123 | _cls = cls;
124 | unsigned int count;
125 | objc_property_t *t = class_copyPropertyList(cls, &count);
126 | for (int num = 0; num < count; num++) {
127 | LJObjectInformation *objectInfo = [[LJObjectInformation alloc]initWithProperty:t[num]];
128 | [self.objectInfoDic setValue:objectInfo forKey:[NSString stringWithUTF8String:property_getName(t[num])]];
129 | }
130 | [self initializeObjectInfoCacheDic];
131 | [objectInfoCacheDic setValue:self forKey:NSStringFromClass(cls)];
132 | free(t);
133 | }
134 | return self;
135 | }
136 |
137 | -(void)initializeObjectInfoCacheDic
138 | {
139 | static dispatch_once_t onceToken;
140 | dispatch_once(&onceToken, ^{
141 | objectInfoCacheDic = [NSMutableDictionary dictionary];
142 | });
143 | }
144 |
145 | - (BOOL)isCacheWithClass:(Class)cls
146 | {
147 | if ([objectInfoCacheDic objectForKey:NSStringFromClass(cls)]) {
148 | return YES;
149 | }
150 | return NO;
151 | }
152 |
153 | - (LJClassInformation*)classInfoWithClass:(Class)cls
154 | {
155 | return [objectInfoCacheDic objectForKey:NSStringFromClass(cls)];
156 | }
157 |
158 | - (LJObjectInformation*)objectInfoWithName:(NSString*)name
159 | {
160 | return _objectInfoDic[name];
161 | }
162 |
163 | @end
164 |
165 |
166 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFSecurityPolicy.h:
--------------------------------------------------------------------------------
1 | // AFSecurityPolicy.h
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 | #import
24 |
25 | typedef NS_ENUM(NSUInteger, AFSSLPinningMode) {
26 | AFSSLPinningModeNone,
27 | AFSSLPinningModePublicKey,
28 | AFSSLPinningModeCertificate,
29 | };
30 |
31 | /**
32 | `AFSecurityPolicy` evaluates server trust against pinned X.509 certificates and public keys over secure connections.
33 |
34 | Adding pinned SSL certificates to your app helps prevent man-in-the-middle attacks and other vulnerabilities. Applications dealing with sensitive customer data or financial information are strongly encouraged to route all communication over an HTTPS connection with SSL pinning configured and enabled.
35 | */
36 | @interface AFSecurityPolicy : NSObject
37 |
38 | /**
39 | The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to `AFSSLPinningModeNone`.
40 | */
41 | @property (readonly, nonatomic, assign) AFSSLPinningMode SSLPinningMode;
42 |
43 | /**
44 | Whether to evaluate an entire SSL certificate chain, or just the leaf certificate. Defaults to `YES`.
45 | */
46 | @property (nonatomic, assign) BOOL validatesCertificateChain;
47 |
48 | /**
49 | The certificates used to evaluate server trust according to the SSL pinning mode. By default, this property is set to any (`.cer`) certificates included in the app bundle.
50 | */
51 | @property (nonatomic, strong) NSArray *pinnedCertificates;
52 |
53 | /**
54 | Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to `NO`.
55 | */
56 | @property (nonatomic, assign) BOOL allowInvalidCertificates;
57 |
58 | /**
59 | Whether or not to validate the domain name in the certificate's CN field. Defaults to `YES`.
60 | */
61 | @property (nonatomic, assign) BOOL validatesDomainName;
62 |
63 | ///-----------------------------------------
64 | /// @name Getting Specific Security Policies
65 | ///-----------------------------------------
66 |
67 | /**
68 | Returns the shared default security policy, which does not allow invalid certificates, validates domain name, and does not validate against pinned certificates or public keys.
69 |
70 | @return The default security policy.
71 | */
72 | + (instancetype)defaultPolicy;
73 |
74 | ///---------------------
75 | /// @name Initialization
76 | ///---------------------
77 |
78 | /**
79 | Creates and returns a security policy with the specified pinning mode.
80 |
81 | @param pinningMode The SSL pinning mode.
82 |
83 | @return A new security policy.
84 | */
85 | + (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode;
86 |
87 | ///------------------------------
88 | /// @name Evaluating Server Trust
89 | ///------------------------------
90 |
91 | /**
92 | Whether or not the specified server trust should be accepted, based on the security policy.
93 |
94 | This method should be used when responding to an authentication challenge from a server.
95 |
96 | @param serverTrust The X.509 certificate trust of the server.
97 |
98 | @return Whether or not to trust the server.
99 |
100 | @warning This method has been deprecated in favor of `-evaluateServerTrust:forDomain:`.
101 | */
102 | - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust DEPRECATED_ATTRIBUTE;
103 |
104 | /**
105 | Whether or not the specified server trust should be accepted, based on the security policy.
106 |
107 | This method should be used when responding to an authentication challenge from a server.
108 |
109 | @param serverTrust The X.509 certificate trust of the server.
110 | @param domain The domain of serverTrust. If `nil`, the domain will not be validated.
111 |
112 | @return Whether or not to trust the server.
113 | */
114 | - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
115 | forDomain:(NSString *)domain;
116 |
117 | @end
118 |
119 | ///----------------
120 | /// @name Constants
121 | ///----------------
122 |
123 | /**
124 | ## SSL Pinning Modes
125 |
126 | The following constants are provided by `AFSSLPinningMode` as possible SSL pinning modes.
127 |
128 | enum {
129 | AFSSLPinningModeNone,
130 | AFSSLPinningModePublicKey,
131 | AFSSLPinningModeCertificate,
132 | }
133 |
134 | `AFSSLPinningModeNone`
135 | Do not used pinned certificates to validate servers.
136 |
137 | `AFSSLPinningModePublicKey`
138 | Validate host certificates against public keys of pinned certificates.
139 |
140 | `AFSSLPinningModeCertificate`
141 | Validate host certificates against pinned certificates.
142 | */
143 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/LJSqliteStatement.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqliteStatement.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/31.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "LJSqliteStatement.h"
10 | #import
11 | #import "NSObject+LJModelMethods.h"
12 |
13 | #define CREATE_TABLENAME_HEADER @"CREATE TABLE IF NOT EXISTS "
14 | #define INSERT_HEADER @"INSERT INTO "
15 | #define UPDATE_HEADER @"UPDATE "
16 | #define DELETE_HEADER @"DELETE FROM "
17 | #define SELECT_HEADER @"SELECT * FROM "
18 |
19 | @implementation LJSqliteStatement
20 |
21 | NSString* createTableString(Class modelClass)
22 | {
23 | NSMutableString* sqlString = [NSMutableString stringWithString:CREATE_TABLENAME_HEADER];
24 | NSDictionary* stateMentDic = [modelClass getAllPropertyNameAndType];
25 | [sqlString appendString:NSStringFromClass(modelClass)];
26 | NSMutableString* valueStr = [NSMutableString string];
27 | [stateMentDic enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSString* obj, BOOL* stop) {
28 | [valueStr appendString:tableNameValueString(obj, key)];
29 | }];
30 | if (valueStr.length>0) {
31 | [valueStr deleteCharactersInRange:NSMakeRange(valueStr.length-1, 1)];
32 | }
33 | [sqlString appendFormat:@"(%@)",valueStr];
34 | return sqlString;
35 | }
36 |
37 | NSString* addColum(id model,NSString *name)
38 | {
39 | NSString* sqlString = [NSString stringWithFormat:@"alter table %@ add %@ %@",NSStringFromClass(model),name,[model getTypeNameWith:name]];
40 | return sqlString;
41 | }
42 |
43 | NSString* insertString(id model)
44 | {
45 | NSMutableString* sqlString = [NSMutableString stringWithString:INSERT_HEADER];
46 | [sqlString appendString:NSStringFromClass([model class])];
47 | NSDictionary* valueDic = [model getAllPropertyNameAndType];
48 | NSMutableString* keyStr = [NSMutableString string];
49 | NSMutableString* valueStr = [NSMutableString string];
50 | for (NSString *key in valueDic.allKeys) {
51 | [keyStr appendFormat:@"%@,",key];
52 | [valueStr appendFormat:@"?,"];
53 | }
54 | [sqlString appendFormat:@"(%@) VALUES (%@)",[keyStr substringToIndex:keyStr.length-1],[valueStr substringToIndex:valueStr.length-1]];
55 | return sqlString;
56 | }
57 |
58 | NSString* insertStringWithDic(id model ,NSDictionary* dic)
59 | {
60 | NSMutableString* sqlString = [NSMutableString stringWithString:INSERT_HEADER];
61 | [sqlString appendString:NSStringFromClass([model class])];
62 | NSMutableString* keyStr = [NSMutableString string];
63 | NSMutableString* valueStr = [NSMutableString string];
64 | for (NSString *key in dic.allKeys) {
65 | [keyStr appendFormat:@"%@,",key];
66 | [valueStr appendFormat:@"?,"];
67 | }
68 | [sqlString appendFormat:@"(%@) VALUES (%@)",[keyStr substringToIndex:keyStr.length-1],[valueStr substringToIndex:valueStr.length-1]];
69 | return sqlString;
70 | }
71 |
72 | NSString* deleteString(Class modelClass,NSDictionary* preDict,BOOL isOr)
73 | {
74 | NSMutableString* deleteStr = [NSMutableString stringWithString:DELETE_HEADER];
75 | [deleteStr appendString:NSStringFromClass(modelClass)];
76 | NSString *preStr;
77 | if (isOr) {
78 | preStr = predicate(modelClass, preDict, @"or");
79 | }else
80 | preStr = predicate(modelClass, preDict, @"and");
81 | if (preStr.length) {
82 | [deleteStr appendFormat:@" WHERE %@",preStr];
83 | }
84 | return deleteStr;
85 | }
86 |
87 | NSString* selectString(Class modelClass,NSDictionary* preDict,NSString *sortStr,BOOL isOr)
88 | {
89 | NSMutableString* selectStr = [NSMutableString stringWithString:SELECT_HEADER];
90 | [selectStr appendString:NSStringFromClass(modelClass)];
91 |
92 | NSString *preStr;
93 | if (isOr) {
94 | preStr = predicate(modelClass, preDict, @"or");
95 | }else
96 | preStr = predicate(modelClass, preDict, @"and");
97 |
98 | if (preStr.length) {
99 | [selectStr appendFormat:@" WHERE %@",preStr];
100 | }
101 | if (sortStr.length) {
102 | [selectStr appendString:sortStr];
103 | }
104 | return selectStr;
105 | }
106 |
107 | NSString* changeString(Class modelClass,NSDictionary* changeDict,NSDictionary* preDict,BOOL isOr)
108 | {
109 | NSMutableString* changeStr = [NSMutableString stringWithString:UPDATE_HEADER];
110 | [changeStr appendString:NSStringFromClass(modelClass)];
111 | NSString *chaStr = predicate(modelClass, changeDict, @",");
112 |
113 | NSString *preStr;
114 | if (isOr) {
115 | preStr = predicate(modelClass, preDict, @"or");
116 | }else
117 | preStr = predicate(modelClass, preDict, @"and");
118 |
119 | if (chaStr.length) {
120 | [changeStr appendFormat:@" SET %@",chaStr];
121 | if (preStr.length) {
122 | [changeStr appendFormat:@" WHERE %@",preStr];
123 | }
124 | return changeStr;
125 | }else
126 | return nil;
127 | }
128 |
129 |
130 | NSString* freedomString(Class modelClass,NSString* predicateString,NSString* changeString,LJStatement freedomStatement)
131 | {
132 | NSMutableString* predicateStr;
133 | switch (freedomStatement) {
134 | case LJAddStatement:
135 | predicateStr = [NSMutableString stringWithString:INSERT_HEADER];
136 | break;
137 | case LJDeleteStatement:
138 | predicateStr = [NSMutableString stringWithString:DELETE_HEADER];
139 | break;
140 | case LJQueryStatement:
141 | predicateStr = [NSMutableString stringWithString:SELECT_HEADER];
142 | break;
143 | case LJChangeStatement:
144 | predicateStr = [NSMutableString stringWithString:UPDATE_HEADER];
145 | break;
146 | default:
147 | return nil;
148 | }
149 | [predicateStr appendString:NSStringFromClass(modelClass)];
150 | if (freedomStatement == LJChangeStatement && changeString.length)
151 | [predicateStr appendFormat:@" SET %@",changeString];
152 |
153 | if (predicateString.length)
154 | [predicateStr appendFormat:@" WHERE %@",predicateString];
155 |
156 | return predicateStr;
157 | }
158 |
159 | NSString* predicate(Class modelClass,NSDictionary* preDict,NSString *link)
160 | {
161 | NSDictionary* stateMentDic = [modelClass determineProperties];
162 | NSMutableString *preStr = [NSMutableString string];
163 | NSArray *preArray = [preDict allKeys];
164 | for (NSString *key in preArray) {
165 | if ([stateMentDic[key] isEqual: @"nsType"]) {
166 | [preStr appendString:[NSString stringWithFormat:@"%@ = '%@' %@",key ,preDict[key], link]];
167 | }else if ([stateMentDic[key] isEqual: @"baseType"]){
168 | [preStr appendString:[NSString stringWithFormat:@"%@ = %@ %@",key ,preDict[key], link]];
169 | }
170 | }
171 | if (preStr.length) {
172 | return [preStr substringToIndex:preStr.length-link.length - 1];
173 | }else
174 | return @"";
175 | }
176 |
177 | static NSString* tableNameValueString(NSString* type,NSString* name)
178 | {
179 | NSString* finalStr = @",";
180 | NSString* typeStr = (NSString*)type;
181 | if ([typeStr isEqualToString:@"i"]) {
182 | return [NSString stringWithFormat:@"%@ %@%@",name,@"INT",finalStr];
183 | }else if ([typeStr isEqualToString:@"f"]) {
184 | return [NSString stringWithFormat:@"%@ %@%@",name,@"FLOAT",finalStr];
185 | }else if ([typeStr isEqualToString:@"B"]) {
186 | return [NSString stringWithFormat:@"%@ %@%@",name,@"BOOL",finalStr];
187 | }else if ([typeStr isEqualToString:@"d"]) {
188 | return [NSString stringWithFormat:@"%@ %@%@",name,@"DOUBLE",finalStr];
189 | }else if ([typeStr isEqualToString:@"q"]) {
190 | return [NSString stringWithFormat:@"%@ %@%@",name,@"LONG",finalStr];
191 | }else if ([typeStr isEqualToString:@"NSData"]||[typeStr isEqualToString:@"UIImage"]) {
192 | return [NSString stringWithFormat:@"%@ %@%@",name,@"BLOB",finalStr];
193 | }else if ([typeStr isEqualToString:@"NSNumber"]){
194 | return [NSString stringWithFormat:@"%@ %@%@",name,@"INT",finalStr];
195 | } else
196 | return [NSString stringWithFormat:@"%@ %@%@",name,@"TEXT",finalStr];
197 | }
198 |
199 | @end
200 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFHTTPRequestOperation.m:
--------------------------------------------------------------------------------
1 | // AFHTTPRequestOperation.m
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "AFHTTPRequestOperation.h"
23 |
24 | static dispatch_queue_t http_request_operation_processing_queue() {
25 | static dispatch_queue_t af_http_request_operation_processing_queue;
26 | static dispatch_once_t onceToken;
27 | dispatch_once(&onceToken, ^{
28 | af_http_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.http-request.processing", DISPATCH_QUEUE_CONCURRENT);
29 | });
30 |
31 | return af_http_request_operation_processing_queue;
32 | }
33 |
34 | static dispatch_group_t http_request_operation_completion_group() {
35 | static dispatch_group_t af_http_request_operation_completion_group;
36 | static dispatch_once_t onceToken;
37 | dispatch_once(&onceToken, ^{
38 | af_http_request_operation_completion_group = dispatch_group_create();
39 | });
40 |
41 | return af_http_request_operation_completion_group;
42 | }
43 |
44 | #pragma mark -
45 |
46 | @interface AFURLConnectionOperation ()
47 | @property (readwrite, nonatomic, strong) NSURLRequest *request;
48 | @property (readwrite, nonatomic, strong) NSURLResponse *response;
49 | @end
50 |
51 | @interface AFHTTPRequestOperation ()
52 | @property (readwrite, nonatomic, strong) NSHTTPURLResponse *response;
53 | @property (readwrite, nonatomic, strong) id responseObject;
54 | @property (readwrite, nonatomic, strong) NSError *responseSerializationError;
55 | @property (readwrite, nonatomic, strong) NSRecursiveLock *lock;
56 | @end
57 |
58 | @implementation AFHTTPRequestOperation
59 | @dynamic response;
60 | @dynamic lock;
61 |
62 | - (instancetype)initWithRequest:(NSURLRequest *)urlRequest {
63 | self = [super initWithRequest:urlRequest];
64 | if (!self) {
65 | return nil;
66 | }
67 |
68 | self.responseSerializer = [AFHTTPResponseSerializer serializer];
69 |
70 | return self;
71 | }
72 |
73 | - (void)setResponseSerializer:(AFHTTPResponseSerializer *)responseSerializer {
74 | NSParameterAssert(responseSerializer);
75 |
76 | [self.lock lock];
77 | _responseSerializer = responseSerializer;
78 | self.responseObject = nil;
79 | self.responseSerializationError = nil;
80 | [self.lock unlock];
81 | }
82 |
83 | - (id)responseObject {
84 | [self.lock lock];
85 | if (!_responseObject && [self isFinished] && !self.error) {
86 | NSError *error = nil;
87 | self.responseObject = [self.responseSerializer responseObjectForResponse:self.response data:self.responseData error:&error];
88 | if (error) {
89 | self.responseSerializationError = error;
90 | }
91 | }
92 | [self.lock unlock];
93 |
94 | return _responseObject;
95 | }
96 |
97 | - (NSError *)error {
98 | if (_responseSerializationError) {
99 | return _responseSerializationError;
100 | } else {
101 | return [super error];
102 | }
103 | }
104 |
105 | #pragma mark - AFHTTPRequestOperation
106 |
107 | - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
108 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
109 | {
110 | // completionBlock is manually nilled out in AFURLConnectionOperation to break the retain cycle.
111 | #pragma clang diagnostic push
112 | #pragma clang diagnostic ignored "-Warc-retain-cycles"
113 | #pragma clang diagnostic ignored "-Wgnu"
114 | self.completionBlock = ^{
115 | if (self.completionGroup) {
116 | dispatch_group_enter(self.completionGroup);
117 | }
118 |
119 | dispatch_async(http_request_operation_processing_queue(), ^{
120 | if (self.error) {
121 | if (failure) {
122 | dispatch_group_async(self.completionGroup ?: http_request_operation_completion_group(), self.completionQueue ?: dispatch_get_main_queue(), ^{
123 | failure(self, self.error);
124 | });
125 | }
126 | } else {
127 | id responseObject = self.responseObject;
128 | if (self.error) {
129 | if (failure) {
130 | dispatch_group_async(self.completionGroup ?: http_request_operation_completion_group(), self.completionQueue ?: dispatch_get_main_queue(), ^{
131 | failure(self, self.error);
132 | });
133 | }
134 | } else {
135 | if (success) {
136 | dispatch_group_async(self.completionGroup ?: http_request_operation_completion_group(), self.completionQueue ?: dispatch_get_main_queue(), ^{
137 | success(self, responseObject);
138 | });
139 | }
140 | }
141 | }
142 |
143 | if (self.completionGroup) {
144 | dispatch_group_leave(self.completionGroup);
145 | }
146 | });
147 | };
148 | #pragma clang diagnostic pop
149 | }
150 |
151 | #pragma mark - AFURLRequestOperation
152 |
153 | - (void)pause {
154 | [super pause];
155 |
156 | u_int64_t offset = 0;
157 | if ([self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey]) {
158 | offset = [(NSNumber *)[self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey] unsignedLongLongValue];
159 | } else {
160 | offset = [(NSData *)[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length];
161 | }
162 |
163 | NSMutableURLRequest *mutableURLRequest = [self.request mutableCopy];
164 | if ([self.response respondsToSelector:@selector(allHeaderFields)] && [[self.response allHeaderFields] valueForKey:@"ETag"]) {
165 | [mutableURLRequest setValue:[[self.response allHeaderFields] valueForKey:@"ETag"] forHTTPHeaderField:@"If-Range"];
166 | }
167 | [mutableURLRequest setValue:[NSString stringWithFormat:@"bytes=%llu-", offset] forHTTPHeaderField:@"Range"];
168 | self.request = mutableURLRequest;
169 | }
170 |
171 | #pragma mark - NSSecureCoding
172 |
173 | + (BOOL)supportsSecureCoding {
174 | return YES;
175 | }
176 |
177 | - (id)initWithCoder:(NSCoder *)decoder {
178 | self = [super initWithCoder:decoder];
179 | if (!self) {
180 | return nil;
181 | }
182 |
183 | self.responseSerializer = [decoder decodeObjectOfClass:[AFHTTPResponseSerializer class] forKey:NSStringFromSelector(@selector(responseSerializer))];
184 |
185 | return self;
186 | }
187 |
188 | - (void)encodeWithCoder:(NSCoder *)coder {
189 | [super encodeWithCoder:coder];
190 |
191 | [coder encodeObject:self.responseSerializer forKey:NSStringFromSelector(@selector(responseSerializer))];
192 | }
193 |
194 | #pragma mark - NSCopying
195 |
196 | - (id)copyWithZone:(NSZone *)zone {
197 | AFHTTPRequestOperation *operation = [super copyWithZone:zone];
198 |
199 | operation.responseSerializer = [self.responseSerializer copyWithZone:zone];
200 | operation.completionQueue = self.completionQueue;
201 | operation.completionGroup = self.completionGroup;
202 |
203 | return operation;
204 | }
205 |
206 | @end
207 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFNetworkReachabilityManager.h:
--------------------------------------------------------------------------------
1 | // AFNetworkReachabilityManager.h
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 | #import
24 |
25 | #ifndef NS_DESIGNATED_INITIALIZER
26 | #if __has_attribute(objc_designated_initializer)
27 | #define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
28 | #else
29 | #define NS_DESIGNATED_INITIALIZER
30 | #endif
31 | #endif
32 |
33 | typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
34 | AFNetworkReachabilityStatusUnknown = -1,
35 | AFNetworkReachabilityStatusNotReachable = 0,
36 | AFNetworkReachabilityStatusReachableViaWWAN = 1,
37 | AFNetworkReachabilityStatusReachableViaWiFi = 2,
38 | };
39 |
40 | /**
41 | `AFNetworkReachabilityManager` monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.
42 |
43 | Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability.
44 |
45 | See Apple's Reachability Sample Code (https://developer.apple.com/library/ios/samplecode/reachability/)
46 |
47 | @warning Instances of `AFNetworkReachabilityManager` must be started with `-startMonitoring` before reachability status can be determined.
48 | */
49 | @interface AFNetworkReachabilityManager : NSObject
50 |
51 | /**
52 | The current network reachability status.
53 | */
54 | @property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
55 |
56 | /**
57 | Whether or not the network is currently reachable.
58 | */
59 | @property (readonly, nonatomic, assign, getter = isReachable) BOOL reachable;
60 |
61 | /**
62 | Whether or not the network is currently reachable via WWAN.
63 | */
64 | @property (readonly, nonatomic, assign, getter = isReachableViaWWAN) BOOL reachableViaWWAN;
65 |
66 | /**
67 | Whether or not the network is currently reachable via WiFi.
68 | */
69 | @property (readonly, nonatomic, assign, getter = isReachableViaWiFi) BOOL reachableViaWiFi;
70 |
71 | ///---------------------
72 | /// @name Initialization
73 | ///---------------------
74 |
75 | /**
76 | Returns the shared network reachability manager.
77 | */
78 | + (instancetype)sharedManager;
79 |
80 | /**
81 | Creates and returns a network reachability manager for the specified domain.
82 |
83 | @param domain The domain used to evaluate network reachability.
84 |
85 | @return An initialized network reachability manager, actively monitoring the specified domain.
86 | */
87 | + (instancetype)managerForDomain:(NSString *)domain;
88 |
89 | /**
90 | Creates and returns a network reachability manager for the socket address.
91 |
92 | @param address The socket address (`sockaddr_in`) used to evaluate network reachability.
93 |
94 | @return An initialized network reachability manager, actively monitoring the specified socket address.
95 | */
96 | + (instancetype)managerForAddress:(const void *)address;
97 |
98 | /**
99 | Initializes an instance of a network reachability manager from the specified reachability object.
100 |
101 | @param reachability The reachability object to monitor.
102 |
103 | @return An initialized network reachability manager, actively monitoring the specified reachability.
104 | */
105 | - (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability NS_DESIGNATED_INITIALIZER;
106 |
107 | ///--------------------------------------------------
108 | /// @name Starting & Stopping Reachability Monitoring
109 | ///--------------------------------------------------
110 |
111 | /**
112 | Starts monitoring for changes in network reachability status.
113 | */
114 | - (void)startMonitoring;
115 |
116 | /**
117 | Stops monitoring for changes in network reachability status.
118 | */
119 | - (void)stopMonitoring;
120 |
121 | ///-------------------------------------------------
122 | /// @name Getting Localized Reachability Description
123 | ///-------------------------------------------------
124 |
125 | /**
126 | Returns a localized string representation of the current network reachability status.
127 | */
128 | - (NSString *)localizedNetworkReachabilityStatusString;
129 |
130 | ///---------------------------------------------------
131 | /// @name Setting Network Reachability Change Callback
132 | ///---------------------------------------------------
133 |
134 | /**
135 | Sets a callback to be executed when the network availability of the `baseURL` host changes.
136 |
137 | @param block A block object to be executed when the network availability of the `baseURL` host changes.. This block has no return value and takes a single argument which represents the various reachability states from the device to the `baseURL`.
138 | */
139 | - (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block;
140 |
141 | @end
142 |
143 | ///----------------
144 | /// @name Constants
145 | ///----------------
146 |
147 | /**
148 | ## Network Reachability
149 |
150 | The following constants are provided by `AFNetworkReachabilityManager` as possible network reachability statuses.
151 |
152 | enum {
153 | AFNetworkReachabilityStatusUnknown,
154 | AFNetworkReachabilityStatusNotReachable,
155 | AFNetworkReachabilityStatusReachableViaWWAN,
156 | AFNetworkReachabilityStatusReachableViaWiFi,
157 | }
158 |
159 | `AFNetworkReachabilityStatusUnknown`
160 | The `baseURL` host reachability is not known.
161 |
162 | `AFNetworkReachabilityStatusNotReachable`
163 | The `baseURL` host cannot be reached.
164 |
165 | `AFNetworkReachabilityStatusReachableViaWWAN`
166 | The `baseURL` host can be reached via a cellular connection, such as EDGE or GPRS.
167 |
168 | `AFNetworkReachabilityStatusReachableViaWiFi`
169 | The `baseURL` host can be reached via a Wi-Fi connection.
170 |
171 | ### Keys for Notification UserInfo Dictionary
172 |
173 | Strings that are used as keys in a `userInfo` dictionary in a network reachability status change notification.
174 |
175 | `AFNetworkingReachabilityNotificationStatusItem`
176 | A key in the userInfo dictionary in a `AFNetworkingReachabilityDidChangeNotification` notification.
177 | The corresponding value is an `NSNumber` object representing the `AFNetworkReachabilityStatus` value for the current reachability status.
178 | */
179 |
180 | ///--------------------
181 | /// @name Notifications
182 | ///--------------------
183 |
184 | /**
185 | Posted when network reachability changes.
186 | This notification assigns no notification object. The `userInfo` dictionary contains an `NSNumber` object under the `AFNetworkingReachabilityNotificationStatusItem` key, representing the `AFNetworkReachabilityStatus` value for the current network reachability.
187 |
188 | @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (`Prefix.pch`).
189 | */
190 | extern NSString * const AFNetworkingReachabilityDidChangeNotification;
191 | extern NSString * const AFNetworkingReachabilityNotificationStatusItem;
192 |
193 | ///--------------------
194 | /// @name Functions
195 | ///--------------------
196 |
197 | /**
198 | Returns a localized string representation of an `AFNetworkReachabilityStatus` value.
199 | */
200 | extern NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status);
201 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJSqlite/LJSqlite.m:
--------------------------------------------------------------------------------
1 | //
2 | // LJSqlite.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/30.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "LJSqlite.h"
10 | #import
11 | #import
12 | #import
13 | #import "NSObject+LJModelMethods.h"
14 |
15 | #define Lock pthread_mutex_lock(&_lock)
16 | #define UnLock pthread_mutex_unlock(&_lock)
17 | #define TryLock pthread_mutex_trylock(&_lock)
18 |
19 | @implementation LJSqlite
20 | {
21 | sqlite3* _db;
22 | pthread_mutex_t _lock;
23 | }
24 |
25 | - (instancetype)initWithPath:(NSString*)dbPath
26 | {
27 | self = [super init];
28 | if (self) {
29 | _sqlPath = dbPath;
30 | pthread_mutex_init(&_lock, NULL); //初始化锁
31 | }
32 | return self;
33 | }
34 |
35 | + (instancetype)sqliteWithPath:(NSString*)dbPath
36 | {
37 | LJSqlite* sqlite = [[LJSqlite alloc] initWithPath:dbPath];
38 | return sqlite;
39 | }
40 |
41 | - (BOOL)openDB
42 | {
43 | if (sqlite3_open([self.sqlPath UTF8String], &_db) == SQLITE_OK) {
44 | return YES;
45 | }else{
46 | sqlite3_close(_db);
47 | return NO;
48 | }
49 | }
50 |
51 | - (void)executeSQLWithSqlstringFromModel:(NSString*)sqlString object:(id)modelOrDict executeType:(LJSqliteType)type success:(success)successBlock fail:(fail)failBlock
52 | {
53 | if (sqlString.length) {
54 | [self executeSQLWithSqlstringFromDictionary:sqlString dictionary:[modelOrDict lj_DictionaryFromModel] executeType:type success:successBlock fail:failBlock];
55 | }
56 | }
57 |
58 | - (void)executeSQLWithSqlstringFromDictionary:(NSString*)sqlString dictionary:(NSDictionary *)dict executeType:(LJSqliteType)type success:(success)successBlock fail:(fail)failBlock
59 | {
60 | if (self.isSync) {
61 | Lock;
62 | }
63 | if (![self openDB]) {
64 |
65 | if (failBlock) {
66 | failBlock([NSError errorWithDomain:@"打开数据库失败" code:0 userInfo:@{}]);
67 | }
68 | // if (self.isSync) {
69 | UnLock;
70 | // }
71 | return;
72 | }
73 | sqlite3_stmt* stmt;
74 | if (type == LJSqliteTypeWrite) {
75 | [self writeToDB:sqlString stmt:stmt modelDic:dict complete:^(NSError *error) {
76 | if (failBlock) {
77 | failBlock(error);
78 | }
79 | }];
80 | }else {
81 | [self readFromDB:sqlString stmt:stmt success:^(NSArray *result) {
82 | if (successBlock) {
83 | successBlock(result);
84 | }
85 | } fail:^(NSError *error) {
86 | if (failBlock) {
87 | failBlock(error);
88 | }
89 | }];
90 | }
91 | sqlite3_close(_db);
92 | }
93 |
94 | - (void)writeToDB:(NSString*)sqlString stmt:(sqlite3_stmt*)stmt modelDic:(NSDictionary *)modelDic complete:(fail)complete
95 | {
96 | if (sqlite3_prepare_v2(_db, [sqlString UTF8String], -1, &stmt, nil) != SQLITE_OK) {
97 | if (complete) {
98 | complete(errorForDataBase(sqlString, _db));
99 | }
100 | sqlite3_finalize(stmt);
101 | UnLock;
102 | return;
103 | }
104 | for (int i=0; i
25 | #import
26 | #import
27 | #import
28 | #import
29 |
30 | NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
31 | NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";
32 |
33 | typedef void (^AFNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status);
34 |
35 | typedef NS_ENUM(NSUInteger, AFNetworkReachabilityAssociation) {
36 | AFNetworkReachabilityForAddress = 1,
37 | AFNetworkReachabilityForAddressPair = 2,
38 | AFNetworkReachabilityForName = 3,
39 | };
40 |
41 | NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status) {
42 | switch (status) {
43 | case AFNetworkReachabilityStatusNotReachable:
44 | return NSLocalizedStringFromTable(@"Not Reachable", @"AFNetworking", nil);
45 | case AFNetworkReachabilityStatusReachableViaWWAN:
46 | return NSLocalizedStringFromTable(@"Reachable via WWAN", @"AFNetworking", nil);
47 | case AFNetworkReachabilityStatusReachableViaWiFi:
48 | return NSLocalizedStringFromTable(@"Reachable via WiFi", @"AFNetworking", nil);
49 | case AFNetworkReachabilityStatusUnknown:
50 | default:
51 | return NSLocalizedStringFromTable(@"Unknown", @"AFNetworking", nil);
52 | }
53 | }
54 |
55 | static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetworkReachabilityFlags flags) {
56 | BOOL isReachable = ((flags & kSCNetworkReachabilityFlagsReachable) != 0);
57 | BOOL needsConnection = ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0);
58 | BOOL canConnectionAutomatically = (((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || ((flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0));
59 | BOOL canConnectWithoutUserInteraction = (canConnectionAutomatically && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0);
60 | BOOL isNetworkReachable = (isReachable && (!needsConnection || canConnectWithoutUserInteraction));
61 |
62 | AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
63 | if (isNetworkReachable == NO) {
64 | status = AFNetworkReachabilityStatusNotReachable;
65 | }
66 | #if TARGET_OS_IPHONE
67 | else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
68 | status = AFNetworkReachabilityStatusReachableViaWWAN;
69 | }
70 | #endif
71 | else {
72 | status = AFNetworkReachabilityStatusReachableViaWiFi;
73 | }
74 |
75 | return status;
76 | }
77 |
78 | static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) {
79 | AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
80 | AFNetworkReachabilityStatusBlock block = (__bridge AFNetworkReachabilityStatusBlock)info;
81 | if (block) {
82 | block(status);
83 | }
84 |
85 |
86 | dispatch_async(dispatch_get_main_queue(), ^{
87 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
88 | NSDictionary *userInfo = @{ AFNetworkingReachabilityNotificationStatusItem: @(status) };
89 | [notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:userInfo];
90 | });
91 |
92 | }
93 |
94 | static const void * AFNetworkReachabilityRetainCallback(const void *info) {
95 | return Block_copy(info);
96 | }
97 |
98 | static void AFNetworkReachabilityReleaseCallback(const void *info) {
99 | if (info) {
100 | Block_release(info);
101 | }
102 | }
103 |
104 | @interface AFNetworkReachabilityManager ()
105 | @property (readwrite, nonatomic, assign) SCNetworkReachabilityRef networkReachability;
106 | @property (readwrite, nonatomic, assign) AFNetworkReachabilityAssociation networkReachabilityAssociation;
107 | @property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
108 | @property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
109 | @end
110 |
111 | @implementation AFNetworkReachabilityManager
112 |
113 | + (instancetype)sharedManager {
114 | static AFNetworkReachabilityManager *_sharedManager = nil;
115 | static dispatch_once_t onceToken;
116 | dispatch_once(&onceToken, ^{
117 | struct sockaddr_in address;
118 | bzero(&address, sizeof(address));
119 | address.sin_len = sizeof(address);
120 | address.sin_family = AF_INET;
121 |
122 | _sharedManager = [self managerForAddress:&address];
123 | });
124 |
125 | return _sharedManager;
126 | }
127 |
128 | + (instancetype)managerForDomain:(NSString *)domain {
129 | SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [domain UTF8String]);
130 |
131 | AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
132 | manager.networkReachabilityAssociation = AFNetworkReachabilityForName;
133 |
134 | return manager;
135 | }
136 |
137 | + (instancetype)managerForAddress:(const void *)address {
138 | SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address);
139 |
140 | AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
141 | manager.networkReachabilityAssociation = AFNetworkReachabilityForAddress;
142 |
143 | return manager;
144 | }
145 |
146 | - (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability {
147 | self = [super init];
148 | if (!self) {
149 | return nil;
150 | }
151 |
152 | self.networkReachability = reachability;
153 | self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
154 |
155 | return self;
156 | }
157 |
158 | - (void)dealloc {
159 | [self stopMonitoring];
160 |
161 | if (_networkReachability) {
162 | CFRelease(_networkReachability);
163 | _networkReachability = NULL;
164 | }
165 | }
166 |
167 | #pragma mark -
168 |
169 | - (BOOL)isReachable {
170 | return [self isReachableViaWWAN] || [self isReachableViaWiFi];
171 | }
172 |
173 | - (BOOL)isReachableViaWWAN {
174 | return self.networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN;
175 | }
176 |
177 | - (BOOL)isReachableViaWiFi {
178 | return self.networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi;
179 | }
180 |
181 | #pragma mark -
182 |
183 | - (void)startMonitoring {
184 | [self stopMonitoring];
185 |
186 | if (!self.networkReachability) {
187 | return;
188 | }
189 |
190 | __weak __typeof(self)weakSelf = self;
191 | AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) {
192 | __strong __typeof(weakSelf)strongSelf = weakSelf;
193 |
194 | strongSelf.networkReachabilityStatus = status;
195 | if (strongSelf.networkReachabilityStatusBlock) {
196 | strongSelf.networkReachabilityStatusBlock(status);
197 | }
198 |
199 | };
200 |
201 | SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
202 | SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
203 | SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
204 |
205 | switch (self.networkReachabilityAssociation) {
206 | case AFNetworkReachabilityForName:
207 | break;
208 | case AFNetworkReachabilityForAddress:
209 | case AFNetworkReachabilityForAddressPair:
210 | default: {
211 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{
212 | SCNetworkReachabilityFlags flags;
213 | SCNetworkReachabilityGetFlags(self.networkReachability, &flags);
214 | AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
215 | dispatch_async(dispatch_get_main_queue(), ^{
216 | callback(status);
217 |
218 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
219 | [notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:@{ AFNetworkingReachabilityNotificationStatusItem: @(status) }];
220 |
221 |
222 | });
223 | });
224 | }
225 | break;
226 | }
227 | }
228 |
229 | - (void)stopMonitoring {
230 | if (!self.networkReachability) {
231 | return;
232 | }
233 |
234 | SCNetworkReachabilityUnscheduleFromRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
235 | }
236 |
237 | #pragma mark -
238 |
239 | - (NSString *)localizedNetworkReachabilityStatusString {
240 | return AFStringFromNetworkReachabilityStatus(self.networkReachabilityStatus);
241 | }
242 |
243 | #pragma mark -
244 |
245 | - (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block {
246 | self.networkReachabilityStatusBlock = block;
247 | }
248 |
249 | #pragma mark - NSKeyValueObserving
250 |
251 | + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
252 | if ([key isEqualToString:@"reachable"] || [key isEqualToString:@"reachableViaWWAN"] || [key isEqualToString:@"reachableViaWiFi"]) {
253 | return [NSSet setWithObject:@"networkReachabilityStatus"];
254 | }
255 |
256 | return [super keyPathsForValuesAffectingValueForKey:key];
257 | }
258 |
259 | @end
260 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFSecurityPolicy.m:
--------------------------------------------------------------------------------
1 | // AFSecurityPolicy.m
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "AFSecurityPolicy.h"
23 |
24 | #import
25 |
26 | #if !defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
27 | static NSData * AFSecKeyGetData(SecKeyRef key) {
28 | CFDataRef data = NULL;
29 |
30 | __Require_noErr_Quiet(SecItemExport(key, kSecFormatUnknown, kSecItemPemArmour, NULL, &data), _out);
31 |
32 | return (__bridge_transfer NSData *)data;
33 |
34 | _out:
35 | if (data) {
36 | CFRelease(data);
37 | }
38 |
39 | return nil;
40 | }
41 | #endif
42 |
43 | static BOOL AFSecKeyIsEqualToKey(SecKeyRef key1, SecKeyRef key2) {
44 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
45 | return [(__bridge id)key1 isEqual:(__bridge id)key2];
46 | #else
47 | return [AFSecKeyGetData(key1) isEqual:AFSecKeyGetData(key2)];
48 | #endif
49 | }
50 |
51 | static id AFPublicKeyForCertificate(NSData *certificate) {
52 | id allowedPublicKey = nil;
53 | SecCertificateRef allowedCertificate;
54 | SecCertificateRef allowedCertificates[1];
55 | CFArrayRef tempCertificates = nil;
56 | SecPolicyRef policy = nil;
57 | SecTrustRef allowedTrust = nil;
58 | SecTrustResultType result;
59 |
60 | allowedCertificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificate);
61 | __Require_Quiet(allowedCertificate != NULL, _out);
62 |
63 | allowedCertificates[0] = allowedCertificate;
64 | tempCertificates = CFArrayCreate(NULL, (const void **)allowedCertificates, 1, NULL);
65 |
66 | policy = SecPolicyCreateBasicX509();
67 | __Require_noErr_Quiet(SecTrustCreateWithCertificates(tempCertificates, policy, &allowedTrust), _out);
68 | __Require_noErr_Quiet(SecTrustEvaluate(allowedTrust, &result), _out);
69 |
70 | allowedPublicKey = (__bridge_transfer id)SecTrustCopyPublicKey(allowedTrust);
71 |
72 | _out:
73 | if (allowedTrust) {
74 | CFRelease(allowedTrust);
75 | }
76 |
77 | if (policy) {
78 | CFRelease(policy);
79 | }
80 |
81 | if (tempCertificates) {
82 | CFRelease(tempCertificates);
83 | }
84 |
85 | if (allowedCertificate) {
86 | CFRelease(allowedCertificate);
87 | }
88 |
89 | return allowedPublicKey;
90 | }
91 |
92 | static BOOL AFServerTrustIsValid(SecTrustRef serverTrust) {
93 | BOOL isValid = NO;
94 | SecTrustResultType result;
95 | __Require_noErr_Quiet(SecTrustEvaluate(serverTrust, &result), _out);
96 |
97 | isValid = (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed);
98 |
99 | _out:
100 | return isValid;
101 | }
102 |
103 | static NSArray * AFCertificateTrustChainForServerTrust(SecTrustRef serverTrust) {
104 | CFIndex certificateCount = SecTrustGetCertificateCount(serverTrust);
105 | NSMutableArray *trustChain = [NSMutableArray arrayWithCapacity:(NSUInteger)certificateCount];
106 |
107 | for (CFIndex i = 0; i < certificateCount; i++) {
108 | SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, i);
109 | [trustChain addObject:(__bridge_transfer NSData *)SecCertificateCopyData(certificate)];
110 | }
111 |
112 | return [NSArray arrayWithArray:trustChain];
113 | }
114 |
115 | static NSArray * AFPublicKeyTrustChainForServerTrust(SecTrustRef serverTrust) {
116 | SecPolicyRef policy = SecPolicyCreateBasicX509();
117 | CFIndex certificateCount = SecTrustGetCertificateCount(serverTrust);
118 | NSMutableArray *trustChain = [NSMutableArray arrayWithCapacity:(NSUInteger)certificateCount];
119 | for (CFIndex i = 0; i < certificateCount; i++) {
120 | SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, i);
121 |
122 | SecCertificateRef someCertificates[] = {certificate};
123 | CFArrayRef certificates = CFArrayCreate(NULL, (const void **)someCertificates, 1, NULL);
124 |
125 | SecTrustRef trust;
126 | __Require_noErr_Quiet(SecTrustCreateWithCertificates(certificates, policy, &trust), _out);
127 |
128 | SecTrustResultType result;
129 | __Require_noErr_Quiet(SecTrustEvaluate(trust, &result), _out);
130 |
131 | [trustChain addObject:(__bridge_transfer id)SecTrustCopyPublicKey(trust)];
132 |
133 | _out:
134 | if (trust) {
135 | CFRelease(trust);
136 | }
137 |
138 | if (certificates) {
139 | CFRelease(certificates);
140 | }
141 |
142 | continue;
143 | }
144 | CFRelease(policy);
145 |
146 | return [NSArray arrayWithArray:trustChain];
147 | }
148 |
149 | #pragma mark -
150 |
151 | @interface AFSecurityPolicy()
152 | @property (readwrite, nonatomic, assign) AFSSLPinningMode SSLPinningMode;
153 | @property (readwrite, nonatomic, strong) NSArray *pinnedPublicKeys;
154 | @end
155 |
156 | @implementation AFSecurityPolicy
157 |
158 | + (NSArray *)defaultPinnedCertificates {
159 | static NSArray *_defaultPinnedCertificates = nil;
160 | static dispatch_once_t onceToken;
161 | dispatch_once(&onceToken, ^{
162 | NSBundle *bundle = [NSBundle bundleForClass:[self class]];
163 | NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"."];
164 |
165 | NSMutableArray *certificates = [NSMutableArray arrayWithCapacity:[paths count]];
166 | for (NSString *path in paths) {
167 | NSData *certificateData = [NSData dataWithContentsOfFile:path];
168 | [certificates addObject:certificateData];
169 | }
170 |
171 | _defaultPinnedCertificates = [[NSArray alloc] initWithArray:certificates];
172 | });
173 |
174 | return _defaultPinnedCertificates;
175 | }
176 |
177 | + (instancetype)defaultPolicy {
178 | AFSecurityPolicy *securityPolicy = [[self alloc] init];
179 | securityPolicy.SSLPinningMode = AFSSLPinningModeNone;
180 |
181 | return securityPolicy;
182 | }
183 |
184 | + (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode {
185 | AFSecurityPolicy *securityPolicy = [[self alloc] init];
186 | securityPolicy.SSLPinningMode = pinningMode;
187 |
188 | [securityPolicy setPinnedCertificates:[self defaultPinnedCertificates]];
189 |
190 | return securityPolicy;
191 | }
192 |
193 | - (id)init {
194 | self = [super init];
195 | if (!self) {
196 | return nil;
197 | }
198 |
199 | self.validatesCertificateChain = YES;
200 | self.validatesDomainName = YES;
201 |
202 | return self;
203 | }
204 |
205 | - (void)setPinnedCertificates:(NSArray *)pinnedCertificates {
206 | _pinnedCertificates = pinnedCertificates;
207 |
208 | if (self.pinnedCertificates) {
209 | NSMutableArray *mutablePinnedPublicKeys = [NSMutableArray arrayWithCapacity:[self.pinnedCertificates count]];
210 | for (NSData *certificate in self.pinnedCertificates) {
211 | id publicKey = AFPublicKeyForCertificate(certificate);
212 | if (!publicKey) {
213 | continue;
214 | }
215 | [mutablePinnedPublicKeys addObject:publicKey];
216 | }
217 | self.pinnedPublicKeys = [NSArray arrayWithArray:mutablePinnedPublicKeys];
218 | } else {
219 | self.pinnedPublicKeys = nil;
220 | }
221 | }
222 |
223 | #pragma mark -
224 |
225 | - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust {
226 | return [self evaluateServerTrust:serverTrust forDomain:nil];
227 | }
228 |
229 | - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
230 | forDomain:(NSString *)domain
231 | {
232 | NSMutableArray *policies = [NSMutableArray array];
233 | if (self.validatesDomainName) {
234 | [policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)];
235 | } else {
236 | [policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()];
237 | }
238 |
239 | SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies);
240 |
241 | if (self.SSLPinningMode == AFSSLPinningModeNone) {
242 | if (self.allowInvalidCertificates || AFServerTrustIsValid(serverTrust)){
243 | return YES;
244 | } else {
245 | return NO;
246 | }
247 | } else if (!AFServerTrustIsValid(serverTrust) && !self.allowInvalidCertificates) {
248 | return NO;
249 | }
250 |
251 | NSArray *serverCertificates = AFCertificateTrustChainForServerTrust(serverTrust);
252 | switch (self.SSLPinningMode) {
253 | case AFSSLPinningModeNone:
254 | default:
255 | return NO;
256 | case AFSSLPinningModeCertificate: {
257 | NSMutableArray *pinnedCertificates = [NSMutableArray array];
258 | for (NSData *certificateData in self.pinnedCertificates) {
259 | [pinnedCertificates addObject:(__bridge_transfer id)SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData)];
260 | }
261 | SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)pinnedCertificates);
262 |
263 | if (!AFServerTrustIsValid(serverTrust)) {
264 | return NO;
265 | }
266 |
267 | if (!self.validatesCertificateChain) {
268 | return YES;
269 | }
270 |
271 | NSUInteger trustedCertificateCount = 0;
272 | for (NSData *trustChainCertificate in serverCertificates) {
273 | if ([self.pinnedCertificates containsObject:trustChainCertificate]) {
274 | trustedCertificateCount++;
275 | }
276 | }
277 |
278 | return trustedCertificateCount == [serverCertificates count];
279 | }
280 | case AFSSLPinningModePublicKey: {
281 | NSUInteger trustedPublicKeyCount = 0;
282 | NSArray *publicKeys = AFPublicKeyTrustChainForServerTrust(serverTrust);
283 | if (!self.validatesCertificateChain && [publicKeys count] > 0) {
284 | publicKeys = @[[publicKeys firstObject]];
285 | }
286 |
287 | for (id trustChainPublicKey in publicKeys) {
288 | for (id pinnedPublicKey in self.pinnedPublicKeys) {
289 | if (AFSecKeyIsEqualToKey((__bridge SecKeyRef)trustChainPublicKey, (__bridge SecKeyRef)pinnedPublicKey)) {
290 | trustedPublicKeyCount += 1;
291 | }
292 | }
293 | }
294 |
295 | return trustedPublicKeyCount > 0 && ((self.validatesCertificateChain && trustedPublicKeyCount == [serverCertificates count]) || (!self.validatesCertificateChain && trustedPublicKeyCount >= 1));
296 | }
297 | }
298 |
299 | return NO;
300 | }
301 |
302 | #pragma mark - NSKeyValueObserving
303 |
304 | + (NSSet *)keyPathsForValuesAffectingPinnedPublicKeys {
305 | return [NSSet setWithObject:@"pinnedCertificates"];
306 | }
307 |
308 | @end
309 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFHTTPRequestOperationManager.m:
--------------------------------------------------------------------------------
1 | // AFHTTPRequestOperationManager.m
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import "AFHTTPRequestOperationManager.h"
25 | #import "AFHTTPRequestOperation.h"
26 |
27 | #import
28 | #import
29 |
30 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
31 | #import
32 | #endif
33 |
34 | @interface AFHTTPRequestOperationManager ()
35 | @property (readwrite, nonatomic, strong) NSURL *baseURL;
36 | @end
37 |
38 | @implementation AFHTTPRequestOperationManager
39 |
40 | + (instancetype)manager {
41 | return [[self alloc] initWithBaseURL:nil];
42 | }
43 |
44 | - (instancetype)init {
45 | return [self initWithBaseURL:nil];
46 | }
47 |
48 | - (instancetype)initWithBaseURL:(NSURL *)url {
49 | self = [super init];
50 | if (!self) {
51 | return nil;
52 | }
53 |
54 | // Ensure terminal slash for baseURL path, so that NSURL +URLWithString:relativeToURL: works as expected
55 | if ([[url path] length] > 0 && ![[url absoluteString] hasSuffix:@"/"]) {
56 | url = [url URLByAppendingPathComponent:@""];
57 | }
58 |
59 | self.baseURL = url;
60 |
61 | self.requestSerializer = [AFHTTPRequestSerializer serializer];
62 | self.responseSerializer = [AFJSONResponseSerializer serializer];
63 |
64 | self.securityPolicy = [AFSecurityPolicy defaultPolicy];
65 |
66 | self.reachabilityManager = [AFNetworkReachabilityManager sharedManager];
67 |
68 | self.operationQueue = [[NSOperationQueue alloc] init];
69 |
70 | self.shouldUseCredentialStorage = YES;
71 |
72 | return self;
73 | }
74 |
75 | #pragma mark -
76 |
77 | #ifdef _SYSTEMCONFIGURATION_H
78 | #endif
79 |
80 | - (void)setRequestSerializer:(AFHTTPRequestSerializer *)requestSerializer {
81 | NSParameterAssert(requestSerializer);
82 |
83 | _requestSerializer = requestSerializer;
84 | }
85 |
86 | - (void)setResponseSerializer:(AFHTTPResponseSerializer *)responseSerializer {
87 | NSParameterAssert(responseSerializer);
88 |
89 | _responseSerializer = responseSerializer;
90 | }
91 |
92 | #pragma mark -
93 |
94 | - (AFHTTPRequestOperation *)HTTPRequestOperationWithHTTPMethod:(NSString *)method
95 | URLString:(NSString *)URLString
96 | parameters:(id)parameters
97 | success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
98 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
99 | {
100 | NSError *serializationError = nil;
101 | NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
102 | if (serializationError) {
103 | if (failure) {
104 | #pragma clang diagnostic push
105 | #pragma clang diagnostic ignored "-Wgnu"
106 | dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
107 | failure(nil, serializationError);
108 | });
109 | #pragma clang diagnostic pop
110 | }
111 |
112 | return nil;
113 | }
114 |
115 | return [self HTTPRequestOperationWithRequest:request success:success failure:failure];
116 | }
117 |
118 | - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request
119 | success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
120 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
121 | {
122 | AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
123 | operation.responseSerializer = self.responseSerializer;
124 | operation.shouldUseCredentialStorage = self.shouldUseCredentialStorage;
125 | operation.credential = self.credential;
126 | operation.securityPolicy = self.securityPolicy;
127 |
128 | [operation setCompletionBlockWithSuccess:success failure:failure];
129 | operation.completionQueue = self.completionQueue;
130 | operation.completionGroup = self.completionGroup;
131 |
132 | return operation;
133 | }
134 |
135 | #pragma mark -
136 |
137 | - (AFHTTPRequestOperation *)GET:(NSString *)URLString
138 | parameters:(id)parameters
139 | success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
140 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
141 | {
142 | AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithHTTPMethod:@"GET" URLString:URLString parameters:parameters success:success failure:failure];
143 |
144 | [self.operationQueue addOperation:operation];
145 |
146 | return operation;
147 | }
148 |
149 | - (AFHTTPRequestOperation *)HEAD:(NSString *)URLString
150 | parameters:(id)parameters
151 | success:(void (^)(AFHTTPRequestOperation *operation))success
152 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
153 | {
154 | AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithHTTPMethod:@"HEAD" URLString:URLString parameters:parameters success:^(AFHTTPRequestOperation *requestOperation, __unused id responseObject) {
155 | if (success) {
156 | success(requestOperation);
157 | }
158 | } failure:failure];
159 |
160 | [self.operationQueue addOperation:operation];
161 |
162 | return operation;
163 | }
164 |
165 | - (AFHTTPRequestOperation *)POST:(NSString *)URLString
166 | parameters:(id)parameters
167 | success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
168 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
169 | {
170 | AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithHTTPMethod:@"POST" URLString:URLString parameters:parameters success:success failure:failure];
171 |
172 | [self.operationQueue addOperation:operation];
173 |
174 | return operation;
175 | }
176 |
177 | - (AFHTTPRequestOperation *)POST:(NSString *)URLString
178 | parameters:(id)parameters
179 | constructingBodyWithBlock:(void (^)(id formData))block
180 | success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
181 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
182 | {
183 | NSError *serializationError = nil;
184 | NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError];
185 | if (serializationError) {
186 | if (failure) {
187 | #pragma clang diagnostic push
188 | #pragma clang diagnostic ignored "-Wgnu"
189 | dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
190 | failure(nil, serializationError);
191 | });
192 | #pragma clang diagnostic pop
193 | }
194 |
195 | return nil;
196 | }
197 |
198 | AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
199 |
200 | [self.operationQueue addOperation:operation];
201 |
202 | return operation;
203 | }
204 |
205 | - (AFHTTPRequestOperation *)PUT:(NSString *)URLString
206 | parameters:(id)parameters
207 | success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
208 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
209 | {
210 | AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithHTTPMethod:@"PUT" URLString:URLString parameters:parameters success:success failure:failure];
211 |
212 | [self.operationQueue addOperation:operation];
213 |
214 | return operation;
215 | }
216 |
217 | - (AFHTTPRequestOperation *)PATCH:(NSString *)URLString
218 | parameters:(id)parameters
219 | success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
220 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
221 | {
222 | AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithHTTPMethod:@"PATCH" URLString:URLString parameters:parameters success:success failure:failure];
223 |
224 | [self.operationQueue addOperation:operation];
225 |
226 | return operation;
227 | }
228 |
229 | - (AFHTTPRequestOperation *)DELETE:(NSString *)URLString
230 | parameters:(id)parameters
231 | success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
232 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
233 | {
234 | AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithHTTPMethod:@"DELETE" URLString:URLString parameters:parameters success:success failure:failure];
235 |
236 | [self.operationQueue addOperation:operation];
237 |
238 | return operation;
239 | }
240 |
241 | #pragma mark - NSObject
242 |
243 | - (NSString *)description {
244 | return [NSString stringWithFormat:@"<%@: %p, baseURL: %@, operationQueue: %@>", NSStringFromClass([self class]), self, [self.baseURL absoluteString], self.operationQueue];
245 | }
246 |
247 | #pragma mark - NSSecureCoding
248 |
249 | + (BOOL)supportsSecureCoding {
250 | return YES;
251 | }
252 |
253 | - (id)initWithCoder:(NSCoder *)decoder {
254 | NSURL *baseURL = [decoder decodeObjectForKey:NSStringFromSelector(@selector(baseURL))];
255 |
256 | self = [self initWithBaseURL:baseURL];
257 | if (!self) {
258 | return nil;
259 | }
260 |
261 | self.requestSerializer = [decoder decodeObjectOfClass:[AFHTTPRequestSerializer class] forKey:NSStringFromSelector(@selector(requestSerializer))];
262 | self.responseSerializer = [decoder decodeObjectOfClass:[AFHTTPResponseSerializer class] forKey:NSStringFromSelector(@selector(responseSerializer))];
263 |
264 | return self;
265 | }
266 |
267 | - (void)encodeWithCoder:(NSCoder *)coder {
268 | [coder encodeObject:self.baseURL forKey:NSStringFromSelector(@selector(baseURL))];
269 | [coder encodeObject:self.requestSerializer forKey:NSStringFromSelector(@selector(requestSerializer))];
270 | [coder encodeObject:self.responseSerializer forKey:NSStringFromSelector(@selector(responseSerializer))];
271 | }
272 |
273 | #pragma mark - NSCopying
274 |
275 | - (id)copyWithZone:(NSZone *)zone {
276 | AFHTTPRequestOperationManager *HTTPClient = [[[self class] allocWithZone:zone] initWithBaseURL:self.baseURL];
277 |
278 | HTTPClient.requestSerializer = [self.requestSerializer copyWithZone:zone];
279 | HTTPClient.responseSerializer = [self.responseSerializer copyWithZone:zone];
280 |
281 | return HTTPClient;
282 | }
283 |
284 | @end
285 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFURLResponseSerialization.h:
--------------------------------------------------------------------------------
1 | // AFURLResponseSerialization.h
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 | #import
24 |
25 | /**
26 | The `AFURLResponseSerialization` protocol is adopted by an object that decodes data into a more useful object representation, according to details in the server response. Response serializers may additionally perform validation on the incoming response and data.
27 |
28 | For example, a JSON response serializer may check for an acceptable status code (`2XX` range) and content type (`application/json`), decoding a valid JSON response into an object.
29 | */
30 | @protocol AFURLResponseSerialization
31 |
32 | /**
33 | The response object decoded from the data associated with a specified response.
34 |
35 | @param response The response to be processed.
36 | @param data The response data to be decoded.
37 | @param error The error that occurred while attempting to decode the response data.
38 |
39 | @return The object decoded from the specified response data.
40 | */
41 | - (id)responseObjectForResponse:(NSURLResponse *)response
42 | data:(NSData *)data
43 | error:(NSError *__autoreleasing *)error;
44 |
45 | @end
46 |
47 | #pragma mark -
48 |
49 | /**
50 | `AFHTTPResponseSerializer` conforms to the `AFURLRequestSerialization` & `AFURLResponseSerialization` protocols, offering a concrete base implementation of query string / URL form-encoded parameter serialization and default request headers, as well as response status code and content type validation.
51 |
52 | Any request or response serializer dealing with HTTP is encouraged to subclass `AFHTTPResponseSerializer` in order to ensure consistent default behavior.
53 | */
54 | @interface AFHTTPResponseSerializer : NSObject
55 |
56 | - (instancetype) init;
57 |
58 | /**
59 | The string encoding used to serialize data received from the server, when no string encoding is specified by the response. `NSUTF8StringEncoding` by default.
60 | */
61 | @property (nonatomic, assign) NSStringEncoding stringEncoding;
62 |
63 | /**
64 | Creates and returns a serializer with default configuration.
65 | */
66 | + (instancetype)serializer;
67 |
68 | ///-----------------------------------------
69 | /// @name Configuring Response Serialization
70 | ///-----------------------------------------
71 |
72 | /**
73 | The acceptable HTTP status codes for responses. When non-`nil`, responses with status codes not contained by the set will result in an error during validation.
74 |
75 | See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
76 | */
77 | @property (nonatomic, copy) NSIndexSet *acceptableStatusCodes;
78 |
79 | /**
80 | The acceptable MIME types for responses. When non-`nil`, responses with a `Content-Type` with MIME types that do not intersect with the set will result in an error during validation.
81 | */
82 | @property (nonatomic, copy) NSSet *acceptableContentTypes;
83 |
84 | /**
85 | Validates the specified response and data.
86 |
87 | In its base implementation, this method checks for an acceptable status code and content type. Subclasses may wish to add other domain-specific checks.
88 |
89 | @param response The response to be validated.
90 | @param data The data associated with the response.
91 | @param error The error that occurred while attempting to validate the response.
92 |
93 | @return `YES` if the response is valid, otherwise `NO`.
94 | */
95 | - (BOOL)validateResponse:(NSHTTPURLResponse *)response
96 | data:(NSData *)data
97 | error:(NSError *__autoreleasing *)error;
98 |
99 | @end
100 |
101 | #pragma mark -
102 |
103 |
104 | /**
105 | `AFJSONResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes JSON responses.
106 |
107 | By default, `AFJSONResponseSerializer` accepts the following MIME types, which includes the official standard, `application/json`, as well as other commonly-used types:
108 |
109 | - `application/json`
110 | - `text/json`
111 | - `text/javascript`
112 | */
113 | @interface AFJSONResponseSerializer : AFHTTPResponseSerializer
114 |
115 | - (instancetype) init;
116 |
117 | /**
118 | Options for reading the response JSON data and creating the Foundation objects. For possible values, see the `NSJSONSerialization` documentation section "NSJSONReadingOptions". `0` by default.
119 | */
120 | @property (nonatomic, assign) NSJSONReadingOptions readingOptions;
121 |
122 | /**
123 | Whether to remove keys with `NSNull` values from response JSON. Defaults to `NO`.
124 | */
125 | @property (nonatomic, assign) BOOL removesKeysWithNullValues;
126 |
127 | /**
128 | Creates and returns a JSON serializer with specified reading and writing options.
129 |
130 | @param readingOptions The specified JSON reading options.
131 | */
132 | + (instancetype)serializerWithReadingOptions:(NSJSONReadingOptions)readingOptions;
133 |
134 | @end
135 |
136 | #pragma mark -
137 |
138 | /**
139 | `AFXMLParserResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes XML responses as an `NSXMLParser` objects.
140 |
141 | By default, `AFXMLParserResponseSerializer` accepts the following MIME types, which includes the official standard, `application/xml`, as well as other commonly-used types:
142 |
143 | - `application/xml`
144 | - `text/xml`
145 | */
146 | @interface AFXMLParserResponseSerializer : AFHTTPResponseSerializer
147 |
148 | @end
149 |
150 | #pragma mark -
151 |
152 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
153 |
154 | /**
155 | `AFXMLDocumentResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes XML responses as an `NSXMLDocument` objects.
156 |
157 | By default, `AFXMLDocumentResponseSerializer` accepts the following MIME types, which includes the official standard, `application/xml`, as well as other commonly-used types:
158 |
159 | - `application/xml`
160 | - `text/xml`
161 | */
162 | @interface AFXMLDocumentResponseSerializer : AFHTTPResponseSerializer
163 |
164 | - (instancetype) init;
165 |
166 | /**
167 | Input and output options specifically intended for `NSXMLDocument` objects. For possible values, see the `NSJSONSerialization` documentation section "NSJSONReadingOptions". `0` by default.
168 | */
169 | @property (nonatomic, assign) NSUInteger options;
170 |
171 | /**
172 | Creates and returns an XML document serializer with the specified options.
173 |
174 | @param mask The XML document options.
175 | */
176 | + (instancetype)serializerWithXMLDocumentOptions:(NSUInteger)mask;
177 |
178 | @end
179 |
180 | #endif
181 |
182 | #pragma mark -
183 |
184 | /**
185 | `AFPropertyListResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes XML responses as an `NSXMLDocument` objects.
186 |
187 | By default, `AFPropertyListResponseSerializer` accepts the following MIME types:
188 |
189 | - `application/x-plist`
190 | */
191 | @interface AFPropertyListResponseSerializer : AFHTTPResponseSerializer
192 |
193 | - (instancetype) init;
194 |
195 | /**
196 | The property list format. Possible values are described in "NSPropertyListFormat".
197 | */
198 | @property (nonatomic, assign) NSPropertyListFormat format;
199 |
200 | /**
201 | The property list reading options. Possible values are described in "NSPropertyListMutabilityOptions."
202 | */
203 | @property (nonatomic, assign) NSPropertyListReadOptions readOptions;
204 |
205 | /**
206 | Creates and returns a property list serializer with a specified format, read options, and write options.
207 |
208 | @param format The property list format.
209 | @param readOptions The property list reading options.
210 | */
211 | + (instancetype)serializerWithFormat:(NSPropertyListFormat)format
212 | readOptions:(NSPropertyListReadOptions)readOptions;
213 |
214 | @end
215 |
216 | #pragma mark -
217 |
218 | /**
219 | `AFImageResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes image responses.
220 |
221 | By default, `AFImageResponseSerializer` accepts the following MIME types, which correspond to the image formats supported by UIImage or NSImage:
222 |
223 | - `image/tiff`
224 | - `image/jpeg`
225 | - `image/gif`
226 | - `image/png`
227 | - `image/ico`
228 | - `image/x-icon`
229 | - `image/bmp`
230 | - `image/x-bmp`
231 | - `image/x-xbitmap`
232 | - `image/x-win-bitmap`
233 | */
234 | @interface AFImageResponseSerializer : AFHTTPResponseSerializer
235 |
236 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
237 | /**
238 | The scale factor used when interpreting the image data to construct `responseImage`. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of scale of the main screen by default, which automatically scales images for retina displays, for instance.
239 | */
240 | @property (nonatomic, assign) CGFloat imageScale;
241 |
242 | /**
243 | Whether to automatically inflate response image data for compressed formats (such as PNG or JPEG). Enabling this can significantly improve drawing performance on iOS when used with `setCompletionBlockWithSuccess:failure:`, as it allows a bitmap representation to be constructed in the background rather than on the main thread. `YES` by default.
244 | */
245 | @property (nonatomic, assign) BOOL automaticallyInflatesResponseImage;
246 | #endif
247 |
248 | @end
249 |
250 | #pragma mark -
251 |
252 | /**
253 | `AFCompoundSerializer` is a subclass of `AFHTTPResponseSerializer` that delegates the response serialization to the first `AFHTTPResponseSerializer` object that returns an object for `responseObjectForResponse:data:error:`, falling back on the default behavior of `AFHTTPResponseSerializer`. This is useful for supporting multiple potential types and structures of server responses with a single serializer.
254 | */
255 | @interface AFCompoundResponseSerializer : AFHTTPResponseSerializer
256 |
257 | /**
258 | The component response serializers.
259 | */
260 | @property (readonly, nonatomic, copy) NSArray *responseSerializers;
261 |
262 | /**
263 | Creates and returns a compound serializer comprised of the specified response serializers.
264 |
265 | @warning Each response serializer specified must be a subclass of `AFHTTPResponseSerializer`, and response to `-validateResponse:data:error:`.
266 | */
267 | + (instancetype)compoundSerializerWithResponseSerializers:(NSArray *)responseSerializers;
268 |
269 | @end
270 |
271 | ///----------------
272 | /// @name Constants
273 | ///----------------
274 |
275 | /**
276 | ## Error Domains
277 |
278 | The following error domain is predefined.
279 |
280 | - `NSString * const AFURLResponseSerializationErrorDomain`
281 |
282 | ### Constants
283 |
284 | `AFURLResponseSerializationErrorDomain`
285 | AFURLResponseSerializer errors. Error codes for `AFURLResponseSerializationErrorDomain` correspond to codes in `NSURLErrorDomain`.
286 | */
287 | extern NSString * const AFURLResponseSerializationErrorDomain;
288 |
289 | /**
290 | ## User info dictionary keys
291 |
292 | These keys may exist in the user info dictionary, in addition to those defined for NSError.
293 |
294 | - `NSString * const AFNetworkingOperationFailingURLResponseErrorKey`
295 | - `NSString * const AFNetworkingOperationFailingURLResponseDataErrorKey`
296 |
297 | ### Constants
298 |
299 | `AFNetworkingOperationFailingURLResponseErrorKey`
300 | The corresponding value is an `NSURLResponse` containing the response of the operation associated with an error. This key is only present in the `AFURLResponseSerializationErrorDomain`.
301 |
302 | `AFNetworkingOperationFailingURLResponseDataErrorKey`
303 | The corresponding value is an `NSData` containing the original data of the operation associated with an error. This key is only present in the `AFURLResponseSerializationErrorDomain`.
304 | */
305 | extern NSString * const AFNetworkingOperationFailingURLResponseErrorKey;
306 |
307 | extern NSString * const AFNetworkingOperationFailingURLResponseDataErrorKey;
308 |
309 |
310 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFHTTPSessionManager.m:
--------------------------------------------------------------------------------
1 | // AFHTTPSessionManager.m
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "AFHTTPSessionManager.h"
23 |
24 | #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090)
25 |
26 | #import "AFURLRequestSerialization.h"
27 | #import "AFURLResponseSerialization.h"
28 |
29 | #import
30 | #import
31 |
32 | #ifdef _SYSTEMCONFIGURATION_H
33 | #import
34 | #import
35 | #import
36 | #import
37 | #import
38 | #endif
39 |
40 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
41 | #import
42 | #endif
43 |
44 | @interface AFHTTPSessionManager ()
45 | @property (readwrite, nonatomic, strong) NSURL *baseURL;
46 | @end
47 |
48 | @implementation AFHTTPSessionManager
49 | @dynamic responseSerializer;
50 |
51 | + (instancetype)manager {
52 | return [[[self class] alloc] initWithBaseURL:nil];
53 | }
54 |
55 | - (instancetype)init {
56 | return [self initWithBaseURL:nil];
57 | }
58 |
59 | - (instancetype)initWithBaseURL:(NSURL *)url {
60 | return [self initWithBaseURL:url sessionConfiguration:nil];
61 | }
62 |
63 | - (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration {
64 | return [self initWithBaseURL:nil sessionConfiguration:configuration];
65 | }
66 |
67 | - (instancetype)initWithBaseURL:(NSURL *)url
68 | sessionConfiguration:(NSURLSessionConfiguration *)configuration
69 | {
70 | self = [super initWithSessionConfiguration:configuration];
71 | if (!self) {
72 | return nil;
73 | }
74 |
75 | // Ensure terminal slash for baseURL path, so that NSURL +URLWithString:relativeToURL: works as expected
76 | if ([[url path] length] > 0 && ![[url absoluteString] hasSuffix:@"/"]) {
77 | url = [url URLByAppendingPathComponent:@""];
78 | }
79 |
80 | self.baseURL = url;
81 |
82 | self.requestSerializer = [AFHTTPRequestSerializer serializer];
83 | self.responseSerializer = [AFJSONResponseSerializer serializer];
84 |
85 | return self;
86 | }
87 |
88 | #pragma mark -
89 |
90 | #ifdef _SYSTEMCONFIGURATION_H
91 | #endif
92 |
93 | - (void)setRequestSerializer:(AFHTTPRequestSerializer *)requestSerializer {
94 | NSParameterAssert(requestSerializer);
95 |
96 | _requestSerializer = requestSerializer;
97 | }
98 |
99 | - (void)setResponseSerializer:(AFHTTPResponseSerializer *)responseSerializer {
100 | NSParameterAssert(responseSerializer);
101 |
102 | [super setResponseSerializer:responseSerializer];
103 | }
104 |
105 | #pragma mark -
106 |
107 | - (NSURLSessionDataTask *)GET:(NSString *)URLString
108 | parameters:(id)parameters
109 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
110 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
111 | {
112 | NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"GET" URLString:URLString parameters:parameters success:success failure:failure];
113 |
114 | [dataTask resume];
115 |
116 | return dataTask;
117 | }
118 |
119 | - (NSURLSessionDataTask *)HEAD:(NSString *)URLString
120 | parameters:(id)parameters
121 | success:(void (^)(NSURLSessionDataTask *task))success
122 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
123 | {
124 | NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"HEAD" URLString:URLString parameters:parameters success:^(NSURLSessionDataTask *task, __unused id responseObject) {
125 | if (success) {
126 | success(task);
127 | }
128 | } failure:failure];
129 |
130 | [dataTask resume];
131 |
132 | return dataTask;
133 | }
134 |
135 | - (NSURLSessionDataTask *)POST:(NSString *)URLString
136 | parameters:(id)parameters
137 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
138 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
139 | {
140 | NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"POST" URLString:URLString parameters:parameters success:success failure:failure];
141 |
142 | [dataTask resume];
143 |
144 | return dataTask;
145 | }
146 |
147 | - (NSURLSessionDataTask *)POST:(NSString *)URLString
148 | parameters:(id)parameters
149 | constructingBodyWithBlock:(void (^)(id formData))block
150 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
151 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
152 | {
153 | NSError *serializationError = nil;
154 | NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError];
155 | if (serializationError) {
156 | if (failure) {
157 | #pragma clang diagnostic push
158 | #pragma clang diagnostic ignored "-Wgnu"
159 | dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
160 | failure(nil, serializationError);
161 | });
162 | #pragma clang diagnostic pop
163 | }
164 |
165 | return nil;
166 | }
167 |
168 | __block NSURLSessionDataTask *task = [self uploadTaskWithStreamedRequest:request progress:nil completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
169 | if (error) {
170 | if (failure) {
171 | failure(task, error);
172 | }
173 | } else {
174 | if (success) {
175 | success(task, responseObject);
176 | }
177 | }
178 | }];
179 |
180 | [task resume];
181 |
182 | return task;
183 | }
184 |
185 | - (NSURLSessionDataTask *)PUT:(NSString *)URLString
186 | parameters:(id)parameters
187 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
188 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
189 | {
190 | NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"PUT" URLString:URLString parameters:parameters success:success failure:failure];
191 |
192 | [dataTask resume];
193 |
194 | return dataTask;
195 | }
196 |
197 | - (NSURLSessionDataTask *)PATCH:(NSString *)URLString
198 | parameters:(id)parameters
199 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
200 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
201 | {
202 | NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"PATCH" URLString:URLString parameters:parameters success:success failure:failure];
203 |
204 | [dataTask resume];
205 |
206 | return dataTask;
207 | }
208 |
209 | - (NSURLSessionDataTask *)DELETE:(NSString *)URLString
210 | parameters:(id)parameters
211 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
212 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
213 | {
214 | NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"DELETE" URLString:URLString parameters:parameters success:success failure:failure];
215 |
216 | [dataTask resume];
217 |
218 | return dataTask;
219 | }
220 |
221 | - (NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
222 | URLString:(NSString *)URLString
223 | parameters:(id)parameters
224 | success:(void (^)(NSURLSessionDataTask *, id))success
225 | failure:(void (^)(NSURLSessionDataTask *, NSError *))failure
226 | {
227 | NSError *serializationError = nil;
228 | NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
229 | if (serializationError) {
230 | if (failure) {
231 | #pragma clang diagnostic push
232 | #pragma clang diagnostic ignored "-Wgnu"
233 | dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
234 | failure(nil, serializationError);
235 | });
236 | #pragma clang diagnostic pop
237 | }
238 |
239 | return nil;
240 | }
241 |
242 | __block NSURLSessionDataTask *dataTask = nil;
243 | dataTask = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
244 | if (error) {
245 | if (failure) {
246 | failure(dataTask, error);
247 | }
248 | } else {
249 | if (success) {
250 | success(dataTask, responseObject);
251 | }
252 | }
253 | }];
254 |
255 | return dataTask;
256 | }
257 |
258 | #pragma mark - NSObject
259 |
260 | - (NSString *)description {
261 | return [NSString stringWithFormat:@"<%@: %p, baseURL: %@, session: %@, operationQueue: %@>", NSStringFromClass([self class]), self, [self.baseURL absoluteString], self.session, self.operationQueue];
262 | }
263 |
264 | #pragma mark - NSSecureCoding
265 |
266 | + (BOOL)supportsSecureCoding {
267 | return YES;
268 | }
269 |
270 | - (id)initWithCoder:(NSCoder *)decoder {
271 | NSURL *baseURL = [decoder decodeObjectOfClass:[NSURL class] forKey:NSStringFromSelector(@selector(baseURL))];
272 | NSURLSessionConfiguration *configuration = [decoder decodeObjectOfClass:[NSURLSessionConfiguration class] forKey:@"sessionConfiguration"];
273 | if (!configuration) {
274 | NSString *configurationIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:@"identifier"];
275 | if (configurationIdentifier) {
276 | #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1100)
277 | configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:configurationIdentifier];
278 | #else
279 | configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:configurationIdentifier];
280 | #endif
281 | }
282 | }
283 |
284 | self = [self initWithBaseURL:baseURL sessionConfiguration:configuration];
285 | if (!self) {
286 | return nil;
287 | }
288 |
289 | self.requestSerializer = [decoder decodeObjectOfClass:[AFHTTPRequestSerializer class] forKey:NSStringFromSelector(@selector(requestSerializer))];
290 | self.responseSerializer = [decoder decodeObjectOfClass:[AFHTTPResponseSerializer class] forKey:NSStringFromSelector(@selector(responseSerializer))];
291 |
292 | return self;
293 | }
294 |
295 | - (void)encodeWithCoder:(NSCoder *)coder {
296 | [super encodeWithCoder:coder];
297 |
298 | [coder encodeObject:self.baseURL forKey:NSStringFromSelector(@selector(baseURL))];
299 | if ([self.session.configuration conformsToProtocol:@protocol(NSCoding)]) {
300 | [coder encodeObject:self.session.configuration forKey:@"sessionConfiguration"];
301 | } else {
302 | [coder encodeObject:self.session.configuration.identifier forKey:@"identifier"];
303 | }
304 | [coder encodeObject:self.requestSerializer forKey:NSStringFromSelector(@selector(requestSerializer))];
305 | [coder encodeObject:self.responseSerializer forKey:NSStringFromSelector(@selector(responseSerializer))];
306 | }
307 |
308 | #pragma mark - NSCopying
309 |
310 | - (id)copyWithZone:(NSZone *)zone {
311 | AFHTTPSessionManager *HTTPClient = [[[self class] allocWithZone:zone] initWithBaseURL:self.baseURL sessionConfiguration:self.session.configuration];
312 |
313 | HTTPClient.requestSerializer = [self.requestSerializer copyWithZone:zone];
314 | HTTPClient.responseSerializer = [self.responseSerializer copyWithZone:zone];
315 |
316 | return HTTPClient;
317 | }
318 |
319 | @end
320 |
321 | #endif
322 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFHTTPSessionManager.h:
--------------------------------------------------------------------------------
1 | // AFHTTPSessionManager.h
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 | #import
24 | #import
25 |
26 | #if __IPHONE_OS_VERSION_MIN_REQUIRED
27 | #import
28 | #else
29 | #import
30 | #endif
31 |
32 | #import "AFURLSessionManager.h"
33 |
34 | #ifndef NS_DESIGNATED_INITIALIZER
35 | #if __has_attribute(objc_designated_initializer)
36 | #define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
37 | #else
38 | #define NS_DESIGNATED_INITIALIZER
39 | #endif
40 | #endif
41 |
42 | /**
43 | `AFHTTPSessionManager` is a subclass of `AFURLSessionManager` with convenience methods for making HTTP requests. When a `baseURL` is provided, requests made with the `GET` / `POST` / et al. convenience methods can be made with relative paths.
44 |
45 | ## Subclassing Notes
46 |
47 | Developers targeting iOS 7 or Mac OS X 10.9 or later that deal extensively with a web service are encouraged to subclass `AFHTTPSessionManager`, providing a class method that returns a shared singleton object on which authentication and other configuration can be shared across the application.
48 |
49 | For developers targeting iOS 6 or Mac OS X 10.8 or earlier, `AFHTTPRequestOperationManager` may be used to similar effect.
50 |
51 | ## Methods to Override
52 |
53 | To change the behavior of all data task operation construction, which is also used in the `GET` / `POST` / et al. convenience methods, override `dataTaskWithRequest:completionHandler:`.
54 |
55 | ## Serialization
56 |
57 | Requests created by an HTTP client will contain default headers and encode parameters according to the `requestSerializer` property, which is an object conforming to ``.
58 |
59 | Responses received from the server are automatically validated and serialized by the `responseSerializers` property, which is an object conforming to ``
60 |
61 | ## URL Construction Using Relative Paths
62 |
63 | For HTTP convenience methods, the request serializer constructs URLs from the path relative to the `-baseURL`, using `NSURL +URLWithString:relativeToURL:`, when provided. If `baseURL` is `nil`, `path` needs to resolve to a valid `NSURL` object using `NSURL +URLWithString:`.
64 |
65 | Below are a few examples of how `baseURL` and relative paths interact:
66 |
67 | NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
68 | [NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo
69 | [NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz
70 | [NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo
71 | [NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo
72 | [NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/
73 | [NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/
74 |
75 | Also important to note is that a trailing slash will be added to any `baseURL` without one. This would otherwise cause unexpected behavior when constructing URLs using paths without a leading slash.
76 |
77 | @warning Managers for background sessions must be owned for the duration of their use. This can be accomplished by creating an application-wide or shared singleton instance.
78 | */
79 |
80 | #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090)
81 |
82 | @interface AFHTTPSessionManager : AFURLSessionManager
83 |
84 | /**
85 | The URL used to monitor reachability, and construct requests from relative paths in methods like `requestWithMethod:URLString:parameters:`, and the `GET` / `POST` / et al. convenience methods.
86 | */
87 | @property (readonly, nonatomic, strong) NSURL *baseURL;
88 |
89 | /**
90 | Requests created with `requestWithMethod:URLString:parameters:` & `multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:` are constructed with a set of default headers using a parameter serialization specified by this property. By default, this is set to an instance of `AFHTTPRequestSerializer`, which serializes query string parameters for `GET`, `HEAD`, and `DELETE` requests, or otherwise URL-form-encodes HTTP message bodies.
91 |
92 | @warning `requestSerializer` must not be `nil`.
93 | */
94 | @property (nonatomic, strong) AFHTTPRequestSerializer * requestSerializer;
95 |
96 | /**
97 | Responses sent from the server in data tasks created with `dataTaskWithRequest:success:failure:` and run using the `GET` / `POST` / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an instance of `AFJSONResponseSerializer`.
98 |
99 | @warning `responseSerializer` must not be `nil`.
100 | */
101 | @property (nonatomic, strong) AFHTTPResponseSerializer * responseSerializer;
102 |
103 | ///---------------------
104 | /// @name Initialization
105 | ///---------------------
106 |
107 | /**
108 | Creates and returns an `AFHTTPSessionManager` object.
109 | */
110 | + (instancetype)manager;
111 |
112 | /**
113 | Initializes an `AFHTTPSessionManager` object with the specified base URL.
114 |
115 | @param url The base URL for the HTTP client.
116 |
117 | @return The newly-initialized HTTP client
118 | */
119 | - (instancetype)initWithBaseURL:(NSURL *)url;
120 |
121 | /**
122 | Initializes an `AFHTTPSessionManager` object with the specified base URL.
123 |
124 | This is the designated initializer.
125 |
126 | @param url The base URL for the HTTP client.
127 | @param configuration The configuration used to create the managed session.
128 |
129 | @return The newly-initialized HTTP client
130 | */
131 | - (instancetype)initWithBaseURL:(NSURL *)url
132 | sessionConfiguration:(NSURLSessionConfiguration *)configuration NS_DESIGNATED_INITIALIZER;
133 |
134 | ///---------------------------
135 | /// @name Making HTTP Requests
136 | ///---------------------------
137 |
138 | /**
139 | Creates and runs an `NSURLSessionDataTask` with a `GET` request.
140 |
141 | @param URLString The URL string used to create the request URL.
142 | @param parameters The parameters to be encoded according to the client request serializer.
143 | @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
144 | @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
145 |
146 | @see -dataTaskWithRequest:completionHandler:
147 | */
148 | - (NSURLSessionDataTask *)GET:(NSString *)URLString
149 | parameters:(id)parameters
150 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
151 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
152 |
153 | /**
154 | Creates and runs an `NSURLSessionDataTask` with a `HEAD` request.
155 |
156 | @param URLString The URL string used to create the request URL.
157 | @param parameters The parameters to be encoded according to the client request serializer.
158 | @param success A block object to be executed when the task finishes successfully. This block has no return value and takes a single arguments: the data task.
159 | @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
160 |
161 | @see -dataTaskWithRequest:completionHandler:
162 | */
163 | - (NSURLSessionDataTask *)HEAD:(NSString *)URLString
164 | parameters:(id)parameters
165 | success:(void (^)(NSURLSessionDataTask *task))success
166 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
167 |
168 | /**
169 | Creates and runs an `NSURLSessionDataTask` with a `POST` request.
170 |
171 | @param URLString The URL string used to create the request URL.
172 | @param parameters The parameters to be encoded according to the client request serializer.
173 | @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
174 | @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
175 |
176 | @see -dataTaskWithRequest:completionHandler:
177 | */
178 | - (NSURLSessionDataTask *)POST:(NSString *)URLString
179 | parameters:(id)parameters
180 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
181 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
182 |
183 | /**
184 | Creates and runs an `NSURLSessionDataTask` with a multipart `POST` request.
185 |
186 | @param URLString The URL string used to create the request URL.
187 | @param parameters The parameters to be encoded according to the client request serializer.
188 | @param block A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the `AFMultipartFormData` protocol.
189 | @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
190 | @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
191 |
192 | @see -dataTaskWithRequest:completionHandler:
193 | */
194 | - (NSURLSessionDataTask *)POST:(NSString *)URLString
195 | parameters:(id)parameters
196 | constructingBodyWithBlock:(void (^)(id formData))block
197 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
198 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
199 |
200 | /**
201 | Creates and runs an `NSURLSessionDataTask` with a `PUT` request.
202 |
203 | @param URLString The URL string used to create the request URL.
204 | @param parameters The parameters to be encoded according to the client request serializer.
205 | @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
206 | @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
207 |
208 | @see -dataTaskWithRequest:completionHandler:
209 | */
210 | - (NSURLSessionDataTask *)PUT:(NSString *)URLString
211 | parameters:(id)parameters
212 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
213 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
214 |
215 | /**
216 | Creates and runs an `NSURLSessionDataTask` with a `PATCH` request.
217 |
218 | @param URLString The URL string used to create the request URL.
219 | @param parameters The parameters to be encoded according to the client request serializer.
220 | @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
221 | @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
222 |
223 | @see -dataTaskWithRequest:completionHandler:
224 | */
225 | - (NSURLSessionDataTask *)PATCH:(NSString *)URLString
226 | parameters:(id)parameters
227 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
228 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
229 |
230 | /**
231 | Creates and runs an `NSURLSessionDataTask` with a `DELETE` request.
232 |
233 | @param URLString The URL string used to create the request URL.
234 | @param parameters The parameters to be encoded according to the client request serializer.
235 | @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
236 | @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
237 |
238 | @see -dataTaskWithRequest:completionHandler:
239 | */
240 | - (NSURLSessionDataTask *)DELETE:(NSString *)URLString
241 | parameters:(id)parameters
242 | success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
243 | failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
244 |
245 | @end
246 |
247 | #endif
248 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/AFNetworking/AFURLConnectionOperation.h:
--------------------------------------------------------------------------------
1 | // AFURLConnectionOperation.h
2 | // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 | #import "AFURLRequestSerialization.h"
26 | #import "AFURLResponseSerialization.h"
27 | #import "AFSecurityPolicy.h"
28 |
29 | #ifndef NS_DESIGNATED_INITIALIZER
30 | #if __has_attribute(objc_designated_initializer)
31 | #define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
32 | #else
33 | #define NS_DESIGNATED_INITIALIZER
34 | #endif
35 | #endif
36 |
37 | /**
38 | `AFURLConnectionOperation` is a subclass of `NSOperation` that implements `NSURLConnection` delegate methods.
39 |
40 | ## Subclassing Notes
41 |
42 | This is the base class of all network request operations. You may wish to create your own subclass in order to implement additional `NSURLConnection` delegate methods (see "`NSURLConnection` Delegate Methods" below), or to provide additional properties and/or class constructors.
43 |
44 | If you are creating a subclass that communicates over the HTTP or HTTPS protocols, you may want to consider subclassing `AFHTTPRequestOperation` instead, as it supports specifying acceptable content types or status codes.
45 |
46 | ## NSURLConnection Delegate Methods
47 |
48 | `AFURLConnectionOperation` implements the following `NSURLConnection` delegate methods:
49 |
50 | - `connection:didReceiveResponse:`
51 | - `connection:didReceiveData:`
52 | - `connectionDidFinishLoading:`
53 | - `connection:didFailWithError:`
54 | - `connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:`
55 | - `connection:willCacheResponse:`
56 | - `connectionShouldUseCredentialStorage:`
57 | - `connection:needNewBodyStream:`
58 | - `connection:willSendRequestForAuthenticationChallenge:`
59 |
60 | If any of these methods are overridden in a subclass, they _must_ call the `super` implementation first.
61 |
62 | ## Callbacks and Completion Blocks
63 |
64 | The built-in `completionBlock` provided by `NSOperation` allows for custom behavior to be executed after the request finishes. It is a common pattern for class constructors in subclasses to take callback block parameters, and execute them conditionally in the body of its `completionBlock`. Make sure to handle cancelled operations appropriately when setting a `completionBlock` (i.e. returning early before parsing response data). See the implementation of any of the `AFHTTPRequestOperation` subclasses for an example of this.
65 |
66 | Subclasses are strongly discouraged from overriding `setCompletionBlock:`, as `AFURLConnectionOperation`'s implementation includes a workaround to mitigate retain cycles, and what Apple rather ominously refers to as ["The Deallocation Problem"](http://developer.apple.com/library/ios/#technotes/tn2109/).
67 |
68 | ## SSL Pinning
69 |
70 | Relying on the CA trust model to validate SSL certificates exposes your app to security vulnerabilities, such as man-in-the-middle attacks. For applications that connect to known servers, SSL certificate pinning provides an increased level of security, by checking server certificate validity against those specified in the app bundle.
71 |
72 | SSL with certificate pinning is strongly recommended for any application that transmits sensitive information to an external webservice.
73 |
74 | Connections will be validated on all matching certificates with a `.cer` extension in the bundle root.
75 |
76 | ## App Extensions
77 |
78 | When using AFNetworking in an App Extension, `#define AF_APP_EXTENSIONS` to avoid using unavailable APIs.
79 |
80 | ## NSCoding & NSCopying Conformance
81 |
82 | `AFURLConnectionOperation` conforms to the `NSCoding` and `NSCopying` protocols, allowing operations to be archived to disk, and copied in memory, respectively. However, because of the intrinsic limitations of capturing the exact state of an operation at a particular moment, there are some important caveats to keep in mind:
83 |
84 | ### NSCoding Caveats
85 |
86 | - Encoded operations do not include any block or stream properties. Be sure to set `completionBlock`, `outputStream`, and any callback blocks as necessary when using `-initWithCoder:` or `NSKeyedUnarchiver`.
87 | - Operations are paused on `encodeWithCoder:`. If the operation was encoded while paused or still executing, its archived state will return `YES` for `isReady`. Otherwise, the state of an operation when encoding will remain unchanged.
88 |
89 | ### NSCopying Caveats
90 |
91 | - `-copy` and `-copyWithZone:` return a new operation with the `NSURLRequest` of the original. So rather than an exact copy of the operation at that particular instant, the copying mechanism returns a completely new instance, which can be useful for retrying operations.
92 | - A copy of an operation will not include the `outputStream` of the original.
93 | - Operation copies do not include `completionBlock`, as it often strongly captures a reference to `self`, which would otherwise have the unintuitive side-effect of pointing to the _original_ operation when copied.
94 | */
95 |
96 | @interface AFURLConnectionOperation : NSOperation
97 |
98 | ///-------------------------------
99 | /// @name Accessing Run Loop Modes
100 | ///-------------------------------
101 |
102 | /**
103 | The run loop modes in which the operation will run on the network thread. By default, this is a single-member set containing `NSRunLoopCommonModes`.
104 | */
105 | @property (nonatomic, strong) NSSet *runLoopModes;
106 |
107 | ///-----------------------------------------
108 | /// @name Getting URL Connection Information
109 | ///-----------------------------------------
110 |
111 | /**
112 | The request used by the operation's connection.
113 | */
114 | @property (readonly, nonatomic, strong) NSURLRequest *request;
115 |
116 | /**
117 | The last response received by the operation's connection.
118 | */
119 | @property (readonly, nonatomic, strong) NSURLResponse *response;
120 |
121 | /**
122 | The error, if any, that occurred in the lifecycle of the request.
123 | */
124 | @property (readonly, nonatomic, strong) NSError *error;
125 |
126 | ///----------------------------
127 | /// @name Getting Response Data
128 | ///----------------------------
129 |
130 | /**
131 | The data received during the request.
132 | */
133 | @property (readonly, nonatomic, strong) NSData *responseData;
134 |
135 | /**
136 | The string representation of the response data.
137 | */
138 | @property (readonly, nonatomic, copy) NSString *responseString;
139 |
140 | /**
141 | The string encoding of the response.
142 |
143 | If the response does not specify a valid string encoding, `responseStringEncoding` will return `NSUTF8StringEncoding`.
144 | */
145 | @property (readonly, nonatomic, assign) NSStringEncoding responseStringEncoding;
146 |
147 | ///-------------------------------
148 | /// @name Managing URL Credentials
149 | ///-------------------------------
150 |
151 | /**
152 | Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default.
153 |
154 | This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`.
155 | */
156 | @property (nonatomic, assign) BOOL shouldUseCredentialStorage;
157 |
158 | /**
159 | The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
160 |
161 | This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
162 | */
163 | @property (nonatomic, strong) NSURLCredential *credential;
164 |
165 | ///-------------------------------
166 | /// @name Managing Security Policy
167 | ///-------------------------------
168 |
169 | /**
170 | The security policy used to evaluate server trust for secure connections.
171 | */
172 | @property (nonatomic, strong) AFSecurityPolicy *securityPolicy;
173 |
174 | ///------------------------
175 | /// @name Accessing Streams
176 | ///------------------------
177 |
178 | /**
179 | The input stream used to read data to be sent during the request.
180 |
181 | This property acts as a proxy to the `HTTPBodyStream` property of `request`.
182 | */
183 | @property (nonatomic, strong) NSInputStream *inputStream;
184 |
185 | /**
186 | The output stream that is used to write data received until the request is finished.
187 |
188 | By default, data is accumulated into a buffer that is stored into `responseData` upon completion of the request, with the intermediary `outputStream` property set to `nil`. When `outputStream` is set, the data will not be accumulated into an internal buffer, and as a result, the `responseData` property of the completed request will be `nil`. The output stream will be scheduled in the network thread runloop upon being set.
189 | */
190 | @property (nonatomic, strong) NSOutputStream *outputStream;
191 |
192 | ///---------------------------------
193 | /// @name Managing Callback Queues
194 | ///---------------------------------
195 |
196 | /**
197 | The dispatch queue for `completionBlock`. If `NULL` (default), the main queue is used.
198 | */
199 | #if OS_OBJECT_HAVE_OBJC_SUPPORT
200 | @property (nonatomic, strong) dispatch_queue_t completionQueue;
201 | #else
202 | @property (nonatomic, assign) dispatch_queue_t completionQueue;
203 | #endif
204 |
205 | /**
206 | The dispatch group for `completionBlock`. If `NULL` (default), a private dispatch group is used.
207 | */
208 | #if OS_OBJECT_HAVE_OBJC_SUPPORT
209 | @property (nonatomic, strong) dispatch_group_t completionGroup;
210 | #else
211 | @property (nonatomic, assign) dispatch_group_t completionGroup;
212 | #endif
213 |
214 | ///---------------------------------------------
215 | /// @name Managing Request Operation Information
216 | ///---------------------------------------------
217 |
218 | /**
219 | The user info dictionary for the receiver.
220 | */
221 | @property (nonatomic, strong) NSDictionary *userInfo;
222 |
223 | ///------------------------------------------------------
224 | /// @name Initializing an AFURLConnectionOperation Object
225 | ///------------------------------------------------------
226 |
227 | /**
228 | Initializes and returns a newly allocated operation object with a url connection configured with the specified url request.
229 |
230 | This is the designated initializer.
231 |
232 | @param urlRequest The request object to be used by the operation connection.
233 | */
234 | - (instancetype)initWithRequest:(NSURLRequest *)urlRequest NS_DESIGNATED_INITIALIZER;
235 |
236 | ///----------------------------------
237 | /// @name Pausing / Resuming Requests
238 | ///----------------------------------
239 |
240 | /**
241 | Pauses the execution of the request operation.
242 |
243 | A paused operation returns `NO` for `-isReady`, `-isExecuting`, and `-isFinished`. As such, it will remain in an `NSOperationQueue` until it is either cancelled or resumed. Pausing a finished, cancelled, or paused operation has no effect.
244 | */
245 | - (void)pause;
246 |
247 | /**
248 | Whether the request operation is currently paused.
249 |
250 | @return `YES` if the operation is currently paused, otherwise `NO`.
251 | */
252 | - (BOOL)isPaused;
253 |
254 | /**
255 | Resumes the execution of the paused request operation.
256 |
257 | Pause/Resume behavior varies depending on the underlying implementation for the operation class. In its base implementation, resuming a paused requests restarts the original request. However, since HTTP defines a specification for how to request a specific content range, `AFHTTPRequestOperation` will resume downloading the request from where it left off, instead of restarting the original request.
258 | */
259 | - (void)resume;
260 |
261 | ///----------------------------------------------
262 | /// @name Configuring Backgrounding Task Behavior
263 | ///----------------------------------------------
264 |
265 | /**
266 | Specifies that the operation should continue execution after the app has entered the background, and the expiration handler for that background task.
267 |
268 | @param handler A handler to be called shortly before the application’s remaining background time reaches 0. The handler is wrapped in a block that cancels the operation, and cleans up and marks the end of execution, unlike the `handler` parameter in `UIApplication -beginBackgroundTaskWithExpirationHandler:`, which expects this to be done in the handler itself. The handler is called synchronously on the main thread, thus blocking the application’s suspension momentarily while the application is notified.
269 | */
270 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && !defined(AF_APP_EXTENSIONS)
271 | - (void)setShouldExecuteAsBackgroundTaskWithExpirationHandler:(void (^)(void))handler;
272 | #endif
273 |
274 | ///---------------------------------
275 | /// @name Setting Progress Callbacks
276 | ///---------------------------------
277 |
278 | /**
279 | Sets a callback to be called when an undetermined number of bytes have been uploaded to the server.
280 |
281 | @param block A block object to be called when an undetermined number of bytes have been uploaded to the server. This block has no return value and takes three arguments: the number of bytes written since the last time the upload progress block was called, the total bytes written, and the total bytes expected to be written during the request, as initially determined by the length of the HTTP body. This block may be called multiple times, and will execute on the main thread.
282 | */
283 | - (void)setUploadProgressBlock:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block;
284 |
285 | /**
286 | Sets a callback to be called when an undetermined number of bytes have been downloaded from the server.
287 |
288 | @param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes three arguments: the number of bytes read since the last time the download progress block was called, the total bytes read, and the total bytes expected to be read during the request, as initially determined by the expected content size of the `NSHTTPURLResponse` object. This block may be called multiple times, and will execute on the main thread.
289 | */
290 | - (void)setDownloadProgressBlock:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block;
291 |
292 | ///-------------------------------------------------
293 | /// @name Setting NSURLConnection Delegate Callbacks
294 | ///-------------------------------------------------
295 |
296 | /**
297 | Sets a block to be executed when the connection will authenticate a challenge in order to download its request, as handled by the `NSURLConnectionDelegate` method `connection:willSendRequestForAuthenticationChallenge:`.
298 |
299 | @param block A block object to be executed when the connection will authenticate a challenge in order to download its request. The block has no return type and takes two arguments: the URL connection object, and the challenge that must be authenticated. This block must invoke one of the challenge-responder methods (NSURLAuthenticationChallengeSender protocol).
300 |
301 | If `allowsInvalidSSLCertificate` is set to YES, `connection:willSendRequestForAuthenticationChallenge:` will attempt to have the challenge sender use credentials with invalid SSL certificates.
302 | */
303 | - (void)setWillSendRequestForAuthenticationChallengeBlock:(void (^)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge))block;
304 |
305 | /**
306 | Sets a block to be executed when the server redirects the request from one URL to another URL, or when the request URL changed by the `NSURLProtocol` subclass handling the request in order to standardize its format, as handled by the `NSURLConnectionDataDelegate` method `connection:willSendRequest:redirectResponse:`.
307 |
308 | @param block A block object to be executed when the request URL was changed. The block returns an `NSURLRequest` object, the URL request to redirect, and takes three arguments: the URL connection object, the the proposed redirected request, and the URL response that caused the redirect.
309 | */
310 | - (void)setRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse))block;
311 |
312 |
313 | /**
314 | Sets a block to be executed to modify the response a connection will cache, if any, as handled by the `NSURLConnectionDelegate` method `connection:willCacheResponse:`.
315 |
316 | @param block A block object to be executed to determine what response a connection will cache, if any. The block returns an `NSCachedURLResponse` object, the cached response to store in memory or `nil` to prevent the response from being cached, and takes two arguments: the URL connection object, and the cached response provided for the request.
317 | */
318 | - (void)setCacheResponseBlock:(NSCachedURLResponse * (^)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse))block;
319 |
320 | ///
321 |
322 | /**
323 |
324 | */
325 | + (NSArray *)batchOfRequestOperations:(NSArray *)operations
326 | progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock
327 | completionBlock:(void (^)(NSArray *operations))completionBlock;
328 |
329 | @end
330 |
331 | ///--------------------
332 | /// @name Notifications
333 | ///--------------------
334 |
335 | /**
336 | Posted when an operation begins executing.
337 | */
338 | extern NSString * const AFNetworkingOperationDidStartNotification;
339 |
340 | /**
341 | Posted when an operation finishes.
342 | */
343 | extern NSString * const AFNetworkingOperationDidFinishNotification;
344 |
--------------------------------------------------------------------------------
/LJSqlite/LJSqlite/LJData/LJModel/NSObject+LJModelMethods.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSObject+LJModelMethods.m
3 | // LJSqlite
4 | //
5 | // Created by 宋立军 on 16/3/24.
6 | // Copyright © 2016年 sancaigongsi. All rights reserved.
7 | //
8 |
9 | #import "NSObject+LJModelMethods.h"
10 | #import "LJObjectInformation.h"
11 | #import
12 | #import
13 | #import
14 |
15 | @implementation NSObject (LJModelMethods)
16 |
17 | typedef struct {
18 | void *classInfo;
19 | void *model;
20 | } ModelContext;
21 |
22 | #pragma mark - modelFromObject
23 |
24 | + (NSArray *)lj_ModelArrayFromDictOrJsonArray:(NSArray*)array
25 | {
26 | NSMutableArray *modelArray = [NSMutableArray array];
27 | for (NSDictionary *dict in array) {
28 | [modelArray addObject:[self lj_ModelFromDictionaryOrJson:dict]];
29 | }
30 | return modelArray;
31 | }
32 |
33 | + (id)lj_ModelFromDictionaryOrJson:(id)dicOrJson
34 | {
35 | if (!dicOrJson) return nil;
36 | if ([dicOrJson isKindOfClass:[NSDictionary class]]) {
37 | return [self lj_ModelFromDictionary:(NSDictionary*)dicOrJson];
38 | }
39 | NSData* jsonData;
40 | if ([dicOrJson isKindOfClass:[NSString class]]) {
41 | jsonData = [(NSString*)dicOrJson dataUsingEncoding:NSUTF8StringEncoding];
42 | }else if ([dicOrJson isKindOfClass:[NSData class]])
43 | jsonData = dicOrJson;
44 | if (jsonData) {
45 | return [self lj_ModelFromDictionary:[NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil]];
46 | }
47 | return nil;
48 | }
49 |
50 | + (id)lj_ModelFromDictionary:(NSDictionary*)dic
51 | {
52 | if (!dic ||![dic isKindOfClass:[NSDictionary class]]) return nil;
53 | NSObject *object = [[self alloc]init];
54 | ModelContext modelContext = {0};
55 | LJClassInformation *class = [[LJClassInformation alloc]initWithClass:self];
56 | modelContext.model = (__bridge void *)(object);
57 | modelContext.classInfo = (__bridge void *)(class);
58 | CFDictionaryApplyFunction((__bridge CFDictionaryRef)dic, ModelSetValueToProperty, &modelContext);
59 | return object;
60 | }
61 |
62 | static void ModelSetValueToProperty(const void *key, const void *value, void *context)
63 | {
64 | ModelContext *modelContext = context;
65 | NSString* dicKey = (__bridge NSString *)(key);
66 | id dicValue = (__bridge id)(value);
67 | LJObjectInformation *objectInfo = [((__bridge LJClassInformation*)modelContext->classInfo) objectInfoWithName:dicKey];
68 | NSObject *object = (__bridge NSObject *)modelContext->model;
69 | if (objectInfo.cls) {
70 | setNSTypePropertyValue(object, dicValue, objectInfo.nsTypeEcoding, objectInfo.set);
71 | }else if (objectInfo.type.length){
72 | NSNumber* number = numberWithValue(dicValue);
73 | setBaseTypePropertyValue(object, number, objectInfo.baseTypeEcoding,objectInfo.set);
74 | }
75 | }
76 |
77 | #pragma mark - objectFromModel
78 |
79 | -(NSArray *)lj_DictOrJsonArrayFromModelArray
80 | {
81 | NSMutableArray *dictArray = [NSMutableArray array];
82 | for (id model in (NSArray *)self) {
83 | [dictArray addObject:[model lj_DictionaryFromModel]];
84 | }
85 | return dictArray;
86 | }
87 |
88 | - (NSData *)lj_JsonFromModel{
89 | return [NSJSONSerialization dataWithJSONObject:[self lj_DictionaryFromModel] options:NSJSONWritingPrettyPrinted error:nil];
90 | }
91 |
92 | - (NSDictionary *)lj_DictionaryFromModel
93 | {
94 | if ([self isKindOfClass:[NSArray class]]) {
95 | return nil;
96 | }else if ([self isKindOfClass:[NSDictionary class]]){
97 | return (NSDictionary*)self;
98 | }else if ([self isKindOfClass:[NSString class]]||[self isKindOfClass:[NSData class]]) {
99 | return [NSJSONSerialization JSONObjectWithData:dataFromObject(self) options:NSJSONReadingMutableContainers error:nil];
100 | }else {
101 | NSMutableDictionary* dic = [NSMutableDictionary dictionary];
102 | ModelContext context = {0};
103 | context.classInfo = (__bridge void *)(dic);
104 | context.model = (__bridge void *)(self);
105 | LJClassInformation* classInfo = [[LJClassInformation alloc] initWithClass:object_getClass(self)];
106 | CFDictionaryApplyFunction((__bridge CFMutableDictionaryRef)classInfo.objectInfoDic, ModelGetValueToDic, &context);
107 | return dic;
108 | }
109 | return nil;
110 | }
111 |
112 | static void ModelGetValueToDic(const void* key,const void* value,void* context)
113 | {
114 | ModelContext* modelContext = context;
115 | NSMutableDictionary* dic = (__bridge NSMutableDictionary *)(modelContext->classInfo);
116 | id object = (__bridge id)(modelContext->model);
117 | NSString* dicKey = (__bridge NSString *)(key);
118 | LJObjectInformation* objectInfo = (__bridge LJObjectInformation*)(value);
119 | if (objectInfo) {
120 | if (objectInfo.cls) {
121 | [dic setValue:((id(*)(id,SEL))(void*) objc_msgSend)(object,objectInfo.get) forKey:dicKey];
122 | }else if (objectInfo.type.length>0) {
123 | NSNumber* number = getBaseTypePropertyValue(object, objectInfo.baseTypeEcoding, objectInfo.get);
124 | [dic setValue:number forKey:dicKey];
125 | }
126 | }
127 | }
128 |
129 | static NSNumber* getBaseTypePropertyValue(__unsafe_unretained NSObject* object, NSUInteger type,SEL get)
130 | {
131 | switch (type) {
132 | case LJBaseTypeEcodingINT:
133 |
134 | return @(((int (*)(id, SEL))(void *) objc_msgSend)(object, get));
135 |
136 | case LJBaseTypeEcodingLONG:
137 |
138 | return @(((long (*)(id, SEL))(void *) objc_msgSend)(object,get));
139 |
140 | case LJBaseTypeEcodingULONG:
141 |
142 | return @(((NSUInteger(*)(id,SEL))(void*) objc_msgSend)(object,get));
143 |
144 | case LJBaseTypeEcodingFLOAT:
145 |
146 | return @(((float(*)(id,SEL))(void*) objc_msgSend)(object,get));
147 |
148 | case LJBaseTypeEcodingDOUBLE:
149 |
150 | return @(((double(*)(id,SEL))(void*) objc_msgSend)(object,get));
151 |
152 | case LJBaseTypeEcodingBOOL:
153 |
154 | return @(((BOOL(*)(id,SEL))(void*) objc_msgSend)(object,get));
155 |
156 | case LJBaseTypeEcodingCHAR:
157 |
158 | return @(((char(*)(id,SEL))(void*) objc_msgSend)(object,get));
159 |
160 | default:
161 | return nil;
162 | break;
163 | }
164 | }
165 |
166 | static void setNSTypePropertyValue(__unsafe_unretained id object,__unsafe_unretained id value,LJNSTypeEcoding typeEcoding,SEL set)
167 | {
168 | switch (typeEcoding) {
169 | case LJNSTypeUNknow:
170 | ((void(*)(id,SEL,id))(void*) objc_msgSend)(object,set,value);
171 | break;
172 |
173 | case LJNSTypeNSString:
174 | ((void(*)(id,SEL,id))(void*) objc_msgSend)(object,set,stringFromObject(value));
175 | break;
176 |
177 | case LJNSTypeNSNumber:
178 | ((void(*)(id,SEL,NSNumber*))(void*) objc_msgSend)(object,set,numberWithValue(value));
179 | break;
180 |
181 | case LJNSTypeNSDate:
182 | ((void(*)(id,SEL,NSDate*))(void*) objc_msgSend)(object,set,dateFromObject(value));
183 | break;
184 |
185 | case LJNSTypeNSData:
186 | ((void(*)(id,SEL,NSData*))(void*) objc_msgSend)(object,set,dataFromObject(value));
187 | break;
188 |
189 | case LJNSTypeNSURL:
190 | ((void(*)(id,SEL,NSURL*))(void*) objc_msgSend)(object,set,urlFromObject(value));
191 | break;
192 |
193 | case LJNSTypeNSArray:
194 | ((void(*)(id,SEL,NSArray*))(void*) objc_msgSend)(object,set,arrayFromObject(value));
195 | break;
196 |
197 | case LJNSTypeNSDictionary:
198 | ((void(*)(id,SEL,NSDictionary*))(void*) objc_msgSend)(object,set,dicFromObject(value));
199 | break;
200 |
201 | case LJNSTypeUIImage:
202 | ((void(*)(id,SEL,UIImage*))(void*) objc_msgSend)(object,set,imageFromObject(value));
203 | break;
204 |
205 | default:
206 | break;
207 | }
208 | }
209 |
210 | static void setBaseTypePropertyValue(__unsafe_unretained NSObject* object,__unsafe_unretained NSNumber* value, NSUInteger type,SEL set)
211 | {
212 | switch (type) {
213 | case LJBaseTypeEcodingINT:
214 | ((void (*)(id, SEL, int))(void *) objc_msgSend)(object, set, value.intValue);
215 | break;
216 |
217 | case LJBaseTypeEcodingLONG:
218 | ((void(*)(id,SEL,long))(void*) objc_msgSend)(object,set,value.integerValue);
219 | break;
220 |
221 | case LJBaseTypeEcodingULONG:
222 | ((void(*)(id,SEL,long))(void*) objc_msgSend)(object,set,value.unsignedIntegerValue);
223 | break;
224 |
225 | case LJBaseTypeEcodingFLOAT:
226 | ((void(*)(id,SEL,float))(void*) objc_msgSend)(object,set,value.floatValue);
227 | break;
228 |
229 | case LJBaseTypeEcodingDOUBLE:
230 | ((void(*)(id,SEL,double))(void*) objc_msgSend)(object,set,value.doubleValue);
231 | break;
232 |
233 | case LJBaseTypeEcodingBOOL:
234 | ((void(*)(id,SEL,BOOL))(void*) objc_msgSend)(object,set,value.boolValue);
235 | break;
236 |
237 | case LJBaseTypeEcodingCHAR:
238 | ((void(*)(id,SEL,char))(void*) objc_msgSend)(object,set,value.charValue);
239 | break;
240 |
241 | default:
242 | ((void(*)(id,SEL,id))(void*) objc_msgSend)(object,set,nil);
243 | break;
244 | }
245 | }
246 |
247 | static NSNumber* numberWithValue(__unsafe_unretained id value)
248 | {
249 | if (!value) {
250 | return nil;
251 | }
252 | if ([value isKindOfClass:[NSNumber class]]) return value;
253 | if ([value isKindOfClass:[NSString class]]) {
254 | if ([value containsString:@"."]) {
255 | const char *cstring = ((NSString *)value).UTF8String;
256 | if (!cstring) return nil;
257 | double num = atof(cstring);
258 | if (isnan(num) || isinf(num)) return nil;
259 | return @(num);
260 | }else {
261 | const char *cstring = ((NSString*)value).UTF8String;
262 | if (!cstring) return nil;
263 | return @(atoll(cstring));
264 | }
265 | }
266 | return nil;
267 | }
268 |
269 | static NSDate* dateFromObject(id object)
270 | {
271 | if ([object isKindOfClass:[NSDate class]]) {
272 | return object;
273 | }else if ([object isKindOfClass:[NSString class]]) {
274 | NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
275 | formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
276 | return [formatter dateFromString:object];
277 | }else if ([object isKindOfClass:[NSData class]]) {
278 | NSString* dateStr = [[NSString alloc] initWithData:object encoding:NSUTF8StringEncoding];
279 | NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
280 | formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
281 | return [formatter dateFromString:dateStr];
282 | }else
283 | return object;
284 | }
285 |
286 | static NSString* stringFromObject(id object)
287 | {
288 | if ([object isKindOfClass:[NSString class]]) {
289 | return object;
290 | }else if ([object isKindOfClass:[NSNumber class]]) {
291 | return [object stringValue];
292 | }else if ([object isKindOfClass:[NSData class]]) {
293 | return [[NSString alloc] initWithData:object encoding:NSUTF8StringEncoding];
294 | }else if ([object isKindOfClass:[NSDate class]]) {
295 | NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
296 | formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
297 | return [formatter stringFromDate:object];
298 | }else
299 | return object;
300 | }
301 |
302 | static NSData* dataFromObject(id object)
303 | {
304 | if ([object isKindOfClass:[NSData class]]) {
305 | return object;
306 | }else if ([object isKindOfClass:[NSString class]]) {
307 | return [object dataUsingEncoding:NSUTF8StringEncoding];
308 | }else if ([object isKindOfClass:[NSDate class]]) {
309 | NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
310 | formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
311 | return [[formatter stringFromDate:object] dataUsingEncoding:NSUTF8StringEncoding];
312 | }else if ([object isKindOfClass:[NSArray class]]||[object isKindOfClass:[NSDictionary class]]) {
313 | return [NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingPrettyPrinted error:nil];
314 | }else if ([object isKindOfClass:NSClassFromString(@"UIImage")]) {
315 | return UIImageJPEGRepresentation(object, 1);
316 | }else
317 | return [object dataUsingEncoding:NSUTF8StringEncoding];
318 | }
319 |
320 | static NSURL* urlFromObject(id object)
321 | {
322 | if ([object isKindOfClass:[NSURL class]]) {
323 | return object;
324 | }else if ([object isKindOfClass:[NSString class]]) {
325 | return [NSURL URLWithString:[object stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
326 | }else {
327 | return [NSURL URLWithString:[[[NSString alloc] initWithData:dataFromObject(object) encoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
328 | }
329 | }
330 |
331 | static NSArray* arrayFromObject(id object)
332 | {
333 | if ([object isKindOfClass:[NSArray class]]) {
334 | return object;
335 | }else if ([object isKindOfClass:[NSDictionary class]]){
336 | return nil;
337 | }else {
338 | id value = [NSJSONSerialization JSONObjectWithData:dataFromObject(object) options:NSJSONReadingMutableContainers error:nil];
339 | if ([value isKindOfClass:[NSArray class]]) {
340 | return value;
341 | }
342 | return nil;
343 | }
344 | }
345 |
346 | static NSDictionary* dicFromObject(id object)
347 | {
348 | if ([object isKindOfClass:[NSDictionary class]]) {
349 | return object;
350 | }else {
351 | NSData* data = dataFromObject(object);
352 | id value = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
353 | if ([value isKindOfClass:[NSDictionary class]]) {
354 | return value;
355 | }
356 | return nil;
357 | }
358 | }
359 |
360 | static UIImage* imageFromObject(id object)
361 | {
362 | if ([object isKindOfClass:[UIImage class]]) {
363 | return object;
364 | }else {
365 | return [UIImage imageWithData:dataFromObject(object)];
366 | }
367 | }
368 |
369 | - (NSDictionary*)lj_ModelToDictionary
370 | {
371 | if ([self isKindOfClass:[NSArray class]]) {
372 | return nil;
373 | }else if ([self isKindOfClass:[NSDictionary class]]){
374 | return (NSDictionary*)self;
375 | }else if ([self isKindOfClass:[NSString class]]||[self isKindOfClass:[NSData class]]) {
376 | return [NSJSONSerialization JSONObjectWithData:dataFromObject(self) options:NSJSONReadingMutableContainers error:nil];
377 | }else {
378 | NSMutableDictionary* dic = [NSMutableDictionary dictionary];
379 | ModelContext context = {0};
380 | context.classInfo = (__bridge void *)(dic);
381 | context.model = (__bridge void *)(self);
382 | //判断缓存中是否有这个类的信息
383 | LJClassInformation* classInfo = [[LJClassInformation alloc] initWithClass:object_getClass(self)];
384 | CFDictionaryApplyFunction((__bridge CFMutableDictionaryRef)classInfo.objectInfoDic, ModelGetValueToDic, &context);
385 | return dic;
386 | }
387 | return nil;
388 | }
389 |
390 | + (NSDictionary*)getAllPropertyNameAndType
391 | {
392 | NSMutableDictionary* dic = [NSMutableDictionary dictionary];
393 | unsigned int count = 0;
394 | objc_property_t* property_t = class_copyPropertyList(self, &count);
395 | for (int i=0; i 3) {
419 | [attributeDict setValue:@"nsType" forKey:propertyName];
420 | }else
421 | [attributeDict setValue:@"baseType" forKey:propertyName];
422 | }
423 | return attributeDict;
424 | }
425 |
426 | static id objectType(NSString* typeString)
427 | {
428 | if ([typeString containsString:@"@"]) {
429 | NSArray* strArray = [typeString componentsSeparatedByString:@"\""];
430 | if (strArray.count >= 1) {
431 | return strArray[1];
432 | }else
433 | return nil;
434 | }else
435 | return [typeString substringWithRange:NSMakeRange(1, 1)];
436 | }
437 |
438 | + (NSString*)getTypeNameWith:(NSString*)propertyName
439 | {
440 | NSString* typeStr = [[self getAllPropertyNameAndType]valueForKey:propertyName];
441 | if ([typeStr isEqualToString:@"i"]) {
442 | return @"INT";
443 | }else if ([typeStr isEqualToString:@"f"]) {
444 | return @"FLOAT";
445 | }else if ([typeStr isEqualToString:@"B"]) {
446 | return @"BOOL";
447 | }else if ([typeStr isEqualToString:@"d"]) {
448 | return @"DOUBLE";
449 | }else if ([typeStr isEqualToString:@"q"]) {
450 | return @"LONG";
451 | }else if ([typeStr isEqualToString:@"NSData"]||[typeStr isEqualToString:@"UIImage"]) {
452 | return @"BLOB";
453 | }else if ([typeStr isEqualToString:@"NSNumber"]){
454 | return @"INT";
455 | } else
456 | return @"TEXT";
457 | }
458 |
459 | @end
460 |
461 |
--------------------------------------------------------------------------------