Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
FMYang committed Jan 24, 2021
1 parent fd9a563 commit 5fa43c5
Show file tree
Hide file tree
Showing 18 changed files with 8,648 additions and 4,480 deletions.
10 changes: 10 additions & 0 deletions FMShortVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
889123ED2541F1720024E049 /* douyin_feed.proto in Sources */ = {isa = PBXBuildFile; fileRef = 889123EB2541F1720024E049 /* douyin_feed.proto */; };
889123EE2541F1720024E049 /* douyin_feed in Resources */ = {isa = PBXBuildFile; fileRef = 889123EC2541F1720024E049 /* douyin_feed */; };
DD6845058E62341EC8E8A03B /* libPods-FMShortVideo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C004F412050BC91AE8296B3D /* libPods-FMShortVideo.a */; };
E44EA1D425BAD2FA0017FF30 /* ZYCameraPlayerView.m in Sources */ = {isa = PBXBuildFile; fileRef = E44EA1D325BAD2FA0017FF30 /* ZYCameraPlayerView.m */; };
E4B76CF5253EBC4E00501F05 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E4B76CF4253EBC4E00501F05 /* AppDelegate.m */; };
E4B76D00253EBC5300501F05 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E4B76CFF253EBC5300501F05 /* Assets.xcassets */; };
E4B76D03253EBC5300501F05 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E4B76D01253EBC5300501F05 /* LaunchScreen.storyboard */; };
Expand All @@ -29,6 +30,7 @@
E4B76DA42542CA8A00501F05 /* douyin_userVideo in Resources */ = {isa = PBXBuildFile; fileRef = E4B76DA32542CA8A00501F05 /* douyin_userVideo */; };
E4B76DA82542CD8F00501F05 /* follow_feed in Resources */ = {isa = PBXBuildFile; fileRef = E4B76DA72542CD8F00501F05 /* follow_feed */; };
E4B76DAE2542DE3900501F05 /* FollowFeed.m in Sources */ = {isa = PBXBuildFile; fileRef = E4B76DAD2542DE3900501F05 /* FollowFeed.m */; };
E4B76DB32546613700501F05 /* douyin.protobuf in Resources */ = {isa = PBXBuildFile; fileRef = E4B76DB22546613600501F05 /* douyin.protobuf */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -37,6 +39,8 @@
89F7A8AC1E5EE673DBCF46E3 /* Pods-FMShortVideo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FMShortVideo.debug.xcconfig"; path = "Target Support Files/Pods-FMShortVideo/Pods-FMShortVideo.debug.xcconfig"; sourceTree = "<group>"; };
9861238F409EB91114551610 /* Pods-FMShortVideo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FMShortVideo.release.xcconfig"; path = "Target Support Files/Pods-FMShortVideo/Pods-FMShortVideo.release.xcconfig"; sourceTree = "<group>"; };
C004F412050BC91AE8296B3D /* libPods-FMShortVideo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FMShortVideo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
E44EA1D225BAD2FA0017FF30 /* ZYCameraPlayerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZYCameraPlayerView.h; sourceTree = "<group>"; };
E44EA1D325BAD2FA0017FF30 /* ZYCameraPlayerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZYCameraPlayerView.m; sourceTree = "<group>"; };
E4B76CF0253EBC4E00501F05 /* FMShortVideo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FMShortVideo.app; sourceTree = BUILT_PRODUCTS_DIR; };
E4B76CF3253EBC4E00501F05 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
E4B76CF4253EBC4E00501F05 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -71,6 +75,7 @@
E4B76DA72542CD8F00501F05 /* follow_feed */ = {isa = PBXFileReference; lastKnownFileType = text; path = follow_feed; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.json; };
E4B76DAC2542DE3900501F05 /* FollowFeed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FollowFeed.h; sourceTree = "<group>"; };
E4B76DAD2542DE3900501F05 /* FollowFeed.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FollowFeed.m; sourceTree = "<group>"; };
E4B76DB22546613600501F05 /* douyin.protobuf */ = {isa = PBXFileReference; lastKnownFileType = file; path = douyin.protobuf; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -97,6 +102,7 @@
889123EA2541F1720024E049 /* Resources */ = {
isa = PBXGroup;
children = (
E4B76DB22546613600501F05 /* douyin.protobuf */,
E4B76D9C254293EE00501F05 /* Person.pbobjc.h */,
E4B76D9B254293EE00501F05 /* Person.pbobjc.m */,
E4B76D98254293A200501F05 /* person.proto */,
Expand Down Expand Up @@ -241,6 +247,8 @@
children = (
E4B76D4D253ED85600501F05 /* FMPlayerView.h */,
E4B76D4E253ED85600501F05 /* FMPlayerView.m */,
E44EA1D225BAD2FA0017FF30 /* ZYCameraPlayerView.h */,
E44EA1D325BAD2FA0017FF30 /* ZYCameraPlayerView.m */,
);
path = Util;
sourceTree = "<group>";
Expand Down Expand Up @@ -317,6 +325,7 @@
files = (
E4B76D03253EBC5300501F05 /* LaunchScreen.storyboard in Resources */,
E4B76DA42542CA8A00501F05 /* douyin_userVideo in Resources */,
E4B76DB32546613700501F05 /* douyin.protobuf in Resources */,
E4B76DA82542CD8F00501F05 /* follow_feed in Resources */,
E4B76D00253EBC5300501F05 /* Assets.xcassets in Resources */,
889123EE2541F1720024E049 /* douyin_feed in Resources */,
Expand Down Expand Up @@ -371,6 +380,7 @@
E4B76D822542740000501F05 /* douyin_feed_min.proto in Sources */,
E4B76D06253EBC5300501F05 /* main.m in Sources */,
E4B76D35253EC8BA00501F05 /* VideoModel.m in Sources */,
E44EA1D425BAD2FA0017FF30 /* ZYCameraPlayerView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 7 additions & 1 deletion FMShortVideo/Entry/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@ - (void)initWindow {

- (void)initNetwork {
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
NSLog(@"0 AFNetworkReachabilityManager sharedManager");
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
NSLog(@"1、setReachabilityStatusChangeBlock");
switch (status) {
case AFNetworkReachabilityStatusUnknown:
NSLog(@"AFNetworkReachabilityStatusUnknown");
break;

case AFNetworkReachabilityStatusNotReachable:
NSLog(@"AFNetworkReachabilityStatusNotReachable");
break;

case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"AFNetworkReachabilityStatusReachableViaWWAN || AFNetworkReachabilityStatusReachableViaWiFi");
if(!self.hasAuthNetwork) {
// 发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"networkAuthSuccess" object:nil];
Expand All @@ -62,13 +67,14 @@ - (void)initNetwork {
break;
}
}];
[manager startMonitoring];

FMHttpConfig *config = [FMHttpConfig shared];
config.plugins = @[[FMHttpLogger class]];
config.parse = [[FMParse alloc] init];
config.baseURL = @"https://api.apiopen.top";
config.dataKey = @"result";
config.publicRequestHeaders = @{@"User_Agent": @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36"};
// config.publicRequestHeaders = @{@"User_Agent": @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36"};
config.dataFormat = FMRequestDataFormatJSON;
}

Expand Down
28 changes: 22 additions & 6 deletions FMShortVideo/FMHttpRequest/FMHttpManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ - (nullable NSURLSessionDataTask *)dataTaskWithRequest:(FMRequest *)request
}
}];

NSLog(@"2、dataTaskWithRequest");
// 网络状态判断
if(![self networkReachable]) {
FMError *error = [[FMError alloc] init];
error.reason = FMErrorReasonNetworkLost;
fail(error);
return nil;
}

// mock数据处理
if(request.sampleData) {
FMResponse *fmResponse = [self requestCompletaion:request success:success fail:fail];
Expand Down Expand Up @@ -181,6 +190,7 @@ - (FMResponse *)requestCompletaion:(FMRequest *)request success:(FMSuccessBlock(
fmError.code = @"-1";
fmError.message = @"数据错误";
fmError.data = responseObject;
fmError.reason = FMErrorReasonDataIsNil;
fail(fmError);
}
return nil;
Expand Down Expand Up @@ -208,19 +218,24 @@ - (FMResponse *)process:(id)responseObject success:(FMSuccessBlock(id))success f

FMResponse *fmResponse = nil;
FMError *fmError = nil;

NSLog(@"httpCode = %ld", ((NSHTTPURLResponse *)response).statusCode);

if(error) {
// http请求失败处理
fmError = [FMError processError:error];
fmError.code = responseCode;
fmError.message = message;
fmError.data = data;
fmError.reason = FMErrorReasonServiceError;

if([error.domain isEqualToString:NSURLErrorDomain]) {
if(error.code == NSURLErrorTimedOut) {
// timeout
fmError.reason = FMErrorReasonTimeout;
}
}

// http请求失败处理
fmError = [FMError processError:error];
fmError.code = responseCode;
fmError.message = message;
fmError.data = data;
fail(fmError);
} else {
// http请求成功,业务逻辑处理
Expand Down Expand Up @@ -294,7 +309,8 @@ + (NSURLSessionDataTask *)uploadFile:(FMRequest *)request
}
};

// multipartFormRequestWithMethod最后会调用requestByFinalizingMultipartFormData设置contentType为"multipart/form-data; boundary="
// multipartFormRequestWithMethod最后会调用requestByFinalizingMultipartFormData
// 设置contentType为"multipart/form-data; boundary="
NSMutableURLRequest *uploadRequest = [[FMHttpManager.shared requestSerializer:request] multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:request.path relativeToURL:baseUrl] absoluteString] parameters:request.params constructingBodyWithBlock:bodyBlock error:&serializationError];

[FMHttpManager.shared addHttpHeader:uploadRequest fmRequest:request];
Expand Down
Loading

0 comments on commit 5fa43c5

Please sign in to comment.