Skip to content

Commit

Permalink
merge v2.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Kainosuke Obata committed Jun 15, 2017
2 parents 5207575 + e68a460 commit 943ab6f
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 885 deletions.
642 changes: 0 additions & 642 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions NCMB.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "NCMB"
s.version = "2.3.52"
s.version = "2.3.61"
s.summary = "NCMB is SDK for NIFTY Cloud mobile backend."
s.description = <<-DESC
NCMB is SDK for NIFTY Cloud mobile backend.
Expand All @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.license = "Apache License, Version 2.0"
s.author = "NIFTY Corporation"
s.platform = :ios, "5.1"
s.source = { :git => 'https://github.com/phisz/ncmb_ios.git', :tag => '2.3.52' }
s.source = { :git => 'https://github.com/phisz/ncmb_ios.git', :tag => '2.3.61' }
s.source_files = "NCMB/**/*.{h,m,c}"
s.frameworks = "Foundation", "UIKit", "MobileCoreServices", "AudioToolbox", "SystemConfiguration"
s.requires_arc = true
Expand Down
8 changes: 1 addition & 7 deletions NCMB/NCMBConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#pragma mark - error
#define ERRORDOMAIN @"NCMBErrorDomain"
#define SDK_VERSION @"2.3.5"
#define SDK_VERSION @"2.3.6"

#define DATA_MAIN_PATH [NSHomeDirectory() stringByAppendingPathComponent:@"Library/"]
#define COMMAND_CACHE_FOLDER_PATH [NSString stringWithFormat:@"%@/Private Documents/NCMB/Command Cache/", DATA_MAIN_PATH]
Expand All @@ -42,9 +42,3 @@ typedef void (^NCMBAnyObjectResultBlock)(id object, NSError *error);
typedef void (^NCMBDataResultBlock)(NSData *data, NSError *error);
typedef void (^NCMBDataStreamResultBlock)(NSInputStream *stream, NSError *error);
typedef void (^NCMBProgressBlock)(int percentDone);

//typedef void (^NCMBFetchResultBlock)(BOOL succeeded, NSError *error);
//typedef void (^NCMBSaveResultBlock)(BOOL succeeded, NSError *error);
//typedef void (^NCMBDeleteResultBlock)(BOOL succeeded, NSError *error);
typedef void (^NCMBSaveAllResultBlock)(NSArray *results, NSError *error);
typedef void (^NCMBFetchAllResultBlock)(NSArray *results, NSError *error);
23 changes: 0 additions & 23 deletions NCMB/NCMBObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,6 @@
*/
- (void)saveInBackgroundWithTarget:(id)target selector:(SEL)selector;

/**
objectsにあるNCMBObjectを継承した全てのオブジェクトを保存する。
@param objects 保存するNCMBObjectが含まれる配列
@param error APIリクエストについてのエラー
@return 実行結果の配列を返却する
*/
+ (NSArray*)saveAll:(NSArray*)objects error:(NSError**)error;

/**
objectsにある、NCMBObjectを継承した全てのオブジェクトを非同期通信で保存する。通信後は渡されたblockを実行する
@param objects 保存するNCMBObjectが含まれる配列
@param userBlock 通信後に実行されるblock。引数にNSError *errorを持つ
*/
+ (void)saveAllInBackground:(NSArray*)objects withBlock:(NCMBSaveAllResultBlock)userBlock;

/**
objectsにある、NCMBObjectを継承した全てのオブジェクトを非同期通信で保存する。通信後は指定されたセレクタを実行する
@param objects 保存するNCMBObjectが含まれる配列
@param target APIリクエスト後に実行するターゲット
@param selector APIリクエスト後に実行するセレクタ
*/
+ (void)saveAllInBackground:(NSArray*)objects withTarget:(id)target selector:(SEL)selector;

/**
電波状況を見てmobile backendにオブジェクトを保存する。
Expand Down
202 changes: 0 additions & 202 deletions NCMB/NCMBObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -713,42 +713,6 @@ -(void)afterSave:(NSDictionary*)response operations:(NSMutableDictionary*)operat
[self propertiesFromResponse:response];
}

/**
saveAll実行後の処理を行う
@param objects リクエストされたNCMBObjectの配列
@param operation 各オブジェクトに対する操作履歴
@param response 各オブジェクトに対するレスポンス
@param
**/
+ (void)afterSaveAll:(id)object
operation:(NSMutableDictionary*)operation
response:(NSMutableDictionary*)responseDic
{
if ([[responseDic allKeys] containsObject:@"error"]){
//各オブジェクトがエラーだった場合の処理
NCMBObject *obj = object;
[obj mergePreviousOperation:operation];
} else {
NSDictionary *response = [responseDic objectForKey:@"success"];
if([object isKindOfClass:[NCMBObject class]]){
NCMBObject *obj = object;
[obj afterSave:response operations:operation];
} else if ([object isKindOfClass:[NCMBUser class]]){
NCMBUser *user = object;
[user afterSave:response operations:operation];
} else if ([object isKindOfClass:[NCMBRole class]]){
NCMBRole *role = object;
[role afterSave:response operations:operation];
} else if ([object isKindOfClass:[NCMBPush class]]){
NCMBPush *push = object;
[push afterSave:response operations:operation];
} else if ([object isKindOfClass:[NCMBInstallation class]]){
NCMBInstallation *installation = object;
[installation afterSave:response operations:operation];
}
}
}

/**
mobile backendからエラーが返ってきたときに最新の操作履歴と通信中の操作履歴をマージする
@param operations 最新の操作履歴
Expand Down Expand Up @@ -1152,119 +1116,6 @@ - (void)saveInBackgroundWithTarget:(id)target selector:(SEL)selector{
}];
}

/**
objectsにあるNCMBObjectを継承した全てのオブジェクトを保存する。
@param objects 保存するNCMBObjectが含まれる配列
@param error APIリクエストについてのエラー
@return 実行結果の配列を返却する
*/
+ (NSArray*)saveAll:(NSArray*)objects error:(NSError**)error{
NSMutableArray *requestArray = [NSMutableArray array];
//配列にあるNCMBObjectをJSONに変換
NSMutableArray *operationArray = [NSMutableArray array];
for (id obj in [objects objectEnumerator]){
if ([obj isKindOfClass:[NCMBObject class]]){
NSMutableDictionary *operation = [obj beforeConnection];
[operationArray addObject:operation];
//リクエスト用のNSDictionaryを作成
[requestArray addObject:[obj returnRequestDictionaryForSaveAll:obj operation:operation]];
}
}

NCMBURLConnection *connect = [NCMBObject createConnectionForbatchAPI:requestArray];
if (connect == nil){
return nil;
}

//通信を行う
NSDictionary *response = [connect syncConnection:error];
NSArray *responseArray = [response objectForKey:@"result"];

//それぞれのNCMBObjectのafterSaveを実行する
NSEnumerator *responseEnumerator = [responseArray objectEnumerator];
NSEnumerator *operationEnumerator = [operationArray objectEnumerator];
if (error != nil && *error){
//通信エラー(そもそものmbエラーも含む)があった場合
for (NCMBObject *obj in objects){
[obj mergePreviousOperation:[operationEnumerator nextObject]];
}
} else {
for (id obj in objects){
[NCMBObject afterSaveAll:obj
operation:[operationEnumerator nextObject]
response:[responseEnumerator nextObject]];
}
}
//Dictionaryを返却するけど、objectIdはセットされている状態
return responseArray;
}

/**
objectsにある、NCMBObjectを継承した全てのオブジェクトを非同期通信で保存する。通信後は渡されたblockを実行する
@param objects 保存するNCMBObjectが含まれる配列
@param error APIリクエストについてのエラー
*/
+ (void)saveAllInBackground:(NSArray*)objects withBlock:(NCMBSaveAllResultBlock)userBlock{
NSMutableArray *requestArray = [NSMutableArray array];
//配列にあるNCMBObjectをJSONに変換
NSMutableArray *operationArray = [NSMutableArray array];
for (id obj in [objects objectEnumerator]){
if ([obj isKindOfClass:[NCMBObject class]]){
NSMutableDictionary *operation = [obj beforeConnection];
[operationArray addObject:operation];
//リクエスト用のNSDictionaryを作成
[requestArray addObject:[obj returnRequestDictionaryForSaveAll:obj operation:operation]];
}
}

NCMBURLConnection *connect = [NCMBObject createConnectionForbatchAPI:requestArray];
if (connect == nil){
userBlock(nil, nil);
}
NCMBResultBlock block = ^(NSDictionary *responseDic, NSError *error){
NSArray *responseArray = [responseDic objectForKey:@"result"];
NSEnumerator *responseEnumerator = [responseArray objectEnumerator];
NSEnumerator *operationEnumerator = [operationArray objectEnumerator];
if (error){
//通信エラー(そもそものmbエラーも含む)があった場合
for (NCMBObject *obj in objects){
[obj mergePreviousOperation:[operationEnumerator nextObject]];
}
} else {
//各オブジェクトのレスポンスがエラーだった場合
for (id obj in objects){
[NCMBObject afterSaveAll:obj
operation:[operationEnumerator nextObject]
response:[responseEnumerator nextObject]];
}
}
userBlock(responseArray, error);
};
[connect asyncConnectionWithBlock:block];
}

/**
objectsにある、NCMBObjectを継承した全てのオブジェクトを非同期通信で保存する。通信後は指定されたセレクタを実行する
@param objects 保存するNCMBObjectが含まれる配列
@param target 呼び出すセレクタのターゲット
@param selector 実行するセレクタ
*/
+ (void)saveAllInBackground:(NSArray*)objects withTarget:(id)target selector:(SEL)selector{
if (!target || !selector){
[NSException raise:@"NCMBInvalidValueException" format:@"target or selector must not nil."];
}
NSMethodSignature *signature = [target methodSignatureForSelector:selector];
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:target];
[invocation setSelector:selector];
[NCMBObject saveAllInBackground:objects withBlock:^(NSArray *results, NSError *error) {
[invocation retainArguments];
[invocation setArgument:&results atIndex:2];
[invocation setArgument:&error atIndex:3];
[invocation invoke];
}];
}

/**
save用のNCMBConnectionを作成する
@param url APIリクエストするURL
Expand Down Expand Up @@ -1301,59 +1152,6 @@ - (NCMBURLConnection*)createConnectionForSave:(NSString*)url operation:(NSMutabl
return connect;
}

/**
saveAll用のNCMBURLConnectionを作成する
@param requestArray リクエストするオブジェクトをJSONに変換した配列
@return saveAll用のNCBURLConnection
*/
+ (NCMBURLConnection*)createConnectionForbatchAPI:(NSMutableArray*)requestArray{
//request配列を作成
NSDictionary *requestDic = [NSDictionary dictionaryWithObject:requestArray forKey:@"requests"];
NSError *convertError = nil;
NSData *json = [NSJSONSerialization dataWithJSONObject:requestDic options:kNilOptions error:&convertError];
if (convertError){
return nil;
}
//NCMBConnectionを作成

NSString *path = @"batch";
NSString *method = @"POST";

NCMBURLConnection *connect = [[NCMBURLConnection new] initWithPath:path method:method data:json];
return connect;
}

/**
saveAll用のリクエスト配列を作成する
@param obj リクエストに追加するNCMBObject
@param operation リクエストに追加するオブジェクトの操作履歴
@return ncmbDic リクエスト用のNSDictionary
*/
- (NSDictionary*)returnRequestDictionaryForSaveAll:(NCMBObject*)obj operation:(NSMutableDictionary*)operation {
NSMutableDictionary *operationDic = [obj convertToJSONDicFromOperation:operation];
NSMutableDictionary *ncmbDic = [NSMutableDictionary dictionaryWithObject:[obj convertToJSONFromNCMBObject:operationDic] forKey:@"body"];
if (obj.objectId == nil){
[ncmbDic setObject:@"POST" forKey:@"method"];
} else {
[ncmbDic setObject:@"PUT" forKey:@"method"];
}
[ncmbDic setObject:[self returnRequestUrlForBatchAPI:obj.ncmbClassName objectId:obj.objectId]
forKey:@"path"];
return ncmbDic;
}

/**
クラス名とobjectIdを受け取ってバッチ用APIリクエストURLを作成する
@param ncmbClassName クラス名
@param objectId オブジェクトID
@return バッチ用APIリクエストURL
*/
- (NSString*)returnRequestUrlForBatchAPI:(NSString*)ncmbClassName objectId:(NSString*)objectId{
//ベースのURLを作成
NSString *baseUrl = [self returnBaseUrl:ncmbClassName objectId:objectId];
return [NSString stringWithFormat:@"%@/%@", API_VERSION_V1, baseUrl];
}

/**
電波状況を見てmobile backendにオブジェクトを保存する。
通信できない場合は、次回オンライン時に保存される。
Expand Down
10 changes: 3 additions & 7 deletions NCMB/NCMBURLConnection/NCMBURLConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,9 @@ - (id)convertResponse:(NSData*)contents
return contents;
}

if([self.path isEqualToString:[NSString stringWithFormat:@"/%@/%@", kAPIVersion, @"batch"]]) {
//バッチ処理の場合は配列が返却される
responseDic = [NSDictionary dictionaryWithObject:[self convertResponseToArr:contents error:error] forKey:@"result"];
} else {
//削除の場合は空、それ以外はNSDictionaryが返却される
responseDic = [self convertResponseToDic:contents error:error];
}
//削除の場合は空、それ以外はNSDictionaryが返却される
responseDic = [self convertResponseToDic:contents error:error];

[self signatureCheck:response contentsData:contents error:error];

return responseDic;
Expand Down
2 changes: 1 addition & 1 deletion NCMB/NCMB_Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.3.5</string>
<string>2.3.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion NCMBTests/NCMBTests/NCMBInstallationSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (void)afterFetch:(NSMutableDictionary*)response isRefresh:(BOOL)isRefresh;
},
@"applicationName" : @"aaaa",
@"objectId" : @"EVMu2ne7bjzZhOW2",
@"sdkVersion" : @"2.3.5"
@"sdkVersion" : @"2.3.6"
};

NSDictionary *responseInstallation = @{@"channels" : @[
Expand Down

0 comments on commit 943ab6f

Please sign in to comment.