iOS開発Google Protocol Bufferの解析パッケージ(二)

1797 ワード

そのため、私はGoogle Protocol Bufferのネットワーク解析方法をパッケージしました.プロジェクトの時間が急いでいるので、私はもっと良いパッケージ方法を書いていません.私は創作を続けます.皆さんの励ましと支持を望んでいます.
PBHttpMethod.hのファイル
#import 
@interface PBHttpMethod : NSObject
+(void)postDataByString:(NSString *)urlString BODYData:(NSData *)bodyData WithDataBlock:(void (^)(id data))dataBlock WithResponseBlock:(void (^)(NSURLResponse *response))responseBlock WithErroBlock:(void (^)(NSError *error))errorBlock;
@end

** PBHttpMethod.mのファイル**
#import "PBHttpMethod.h"
#import 
#import "ApiM.pb.h"
@implementation PBHttpMethod
+ (void)postDataByString:(NSString *)urlString BODYData:(NSData *)bodyData WithDataBlock:(void (^)(id))dataBlock WithResponseBlock:(void (^)(NSURLResponse *))responseBlock WithErroBlock:(void (^)(NSError *))errorBlock{
*//URL *
urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:urlString]];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setTimeoutInterval:30];
[request setAllHTTPHeaderFields:nil];
[request setHTTPBody:bodyData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//  , 200 /*  http  */
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSInteger responseStatusCode = [httpResponse statusCode];
NSLog(@" http  %ld", responseStatusCode);
if (responseStatusCode == 200) {
if (error) {
NSLog(@" -<<<<