Skip to content

Commit

Permalink
Video截屏保存相册
Browse files Browse the repository at this point in the history
Change-Id: I7fc7d7f185cd50cd45ee208bb5e8943650cff021
  • Loading branch information
tonychanchen committed May 27, 2021
1 parent 0e05b7b commit 46783a6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/LinkSDKDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
<string>用于获取WiFi信息</string>
<key>NSMicrophoneUsageDescription</key>
<string>获取麦克风权限用于音视频通话</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>用于保存视频截图</string>
<key>UIFileSharingEnabled</key>
<false/>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -56,6 +56,8 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <YYModel.h>
#import "TIoTPlayBackListModel.h"
#import "NSString+Extension.h"
#import "TIoTCoreUtil.h"
#import <IJKMediaFramework/IJKMediaFramework.h>

static NSString * const kPlaybackCellID = @"kPlaybackCellID";
Expand Down Expand Up @@ -189,6 +190,7 @@ - (IBAction)sendFLV:(UIButton *)sender {
}

- (IBAction)dismiss:(id)sender {

[self dismissViewControllerAnimated:YES completion:nil];
}

Expand Down
6 changes: 6 additions & 0 deletions Source/SDK/LinkSDK/QCFoundation/Other/TIoTCoreUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)generateSignature:(NSDictionary *)allParams params:(NSDictionary *)params server:(NSString *)serverHost;

+ (NSString *)qcloudasrutil_sortedJSONTypeQueryParams:(NSDictionary *)params;

/**
截屏
*/
+ (void)screenshotWithView:(UIView *)view;

@end

NS_ASSUME_NONNULL_END
32 changes: 32 additions & 0 deletions Source/SDK/LinkSDK/QCFoundation/Other/TIoTCoreUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,36 @@ + (NSString*)qcloudasrutil_SHA256Hex:(NSString*)source
return ret;
}



//回调方法
+ (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
NSString *msg = nil ;
if(error != NULL){
msg = @"保存图片失败" ;
}else{
msg = @"保存图片成功" ;
}

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
[self.topViewController presentViewController:alert animated:YES completion:nil];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});
});
}

+ (void)screenshotWithView:(UIView *)view {

UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
@end

0 comments on commit 46783a6

Please sign in to comment.