Commit ba88db9e authored by huanglu's avatar huanglu

feat: init

parents
MIT License
Copyright (c) 2019
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<p align="center" >
<img src="https://s2.ax1x.com/2019/05/25/VkQ63T.jpg" title="ScreenRecoderKit">
</p>
[![Platform](https://img.shields.io/cocoapods/p/RTRootNavigationController.svg?style=flat)](http://www.bbc6bae9.com/)
# ScreenRecorderKit
## 注意
现已支持cocoasPods
```objective-c
pod "ScreenRecorderKit"
```
* 注意在开始录屏之前要先获取“图片”的权限,否则回导致,所有接口回调都会正常,但是回调方法中的NSData为空。后续的将权限的判断和索取加入到框架中
* 如果最近有时间的画也会把录屏直播的东西加入进来
## 介绍
ScreenRecorderKit是一个基于ReplayKit封装的轻量级录屏框架。
WWDC关于Replaykit的部分参考:[Go Live with ReplayKit](https://developer.apple.com/videos/play/wwdc2016/601/)
如果直接使用官方的ReplayKit,是没有办法直接获取录制视频的二进制数据的,而是会生成一个预览界面由用户选择保存相册或者是分享,这样的话就很难满足一些业务上的需求,ScreenRecorderKit先把视频存储到相册,然后再从相册中取视频资源转成二进制数据,方便业务上做处理。
本框架帮助开发者以一种更简单的方式处理App间的录屏冲突,App与系统之间的录屏冲突,以及其他异常的提示。并且可以保存到系统相册,代理方法里面可以获取到录屏视频的NSData数据,方便沙盒存储或者上传服务器。
## 特点
* 轻松的处理App与App的录屏冲突、App与系统录屏的冲突、
* 录屏中的异常问题。
* 开始和结束录屏的方法均有成功和失败的回调。
## 使用
1. 引用
在你需要调用录屏功能的地方`ScreenRecordManager.h`
设置 ScreenRecordDelegate 代理`[ScreenRecordManager shareManager];
mgr.screenRecordDelegate = self;`
2. 开始和结束方法
开始录制
```objective-c
[[ScreenRecordManager shareManager] screenRecSuc:^{
NSLog(@"录制启动成功");
[weakself showToast:@"录制启动成功"];
} failure:^(DUErrorHandle *error) {
NSLog(@"%@", error.msg);
[weakself showToast: error.msg];
}];
```
结束录制
```objective-c
[[ScreenRecordManager shareManager] stopRecSuc:^{
} failure:^(DUErrorHandle *error) {
if (error.code == -2) { // -2是没有可以结束的录屏幕的进程
}else{
[weakself showToast: error.msg];
}
}];
```
3. 代理方法
`ScreenRecordManager`的录制状态发生了改变
```objective-c
-(void)recStateDidChange:(RecState)state withError:(NSError *)error{
if (error) {
[self showToast:[error localizedDescription]];
}else{
if (state == RecState_Rec) {
self.recBtn.selected = YES;
}else{
[self showToast:@"录屏结束"];
self.recBtn.selected = NO;
}
}
}
```
`ScreenRecordManager`保存录屏视频到相册成功的代理方法
```objective-c
-(void)savedPhotoImage:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
if(error){
[self showToast:[error localizedDescription]];
}else{
[self showToast:@"保存相册成功"];
}
}
```
`ScreenRecordManager`录屏视频的二进制文件获取,在这里你可以选择将二进制数转成.mp4文件或者将数据上传至服务器等等。
```objective-c
-(void)savedVideoData:(NSData *)data didFinishSavingWithError:(BOOL)isError{
if (isError) {
[self showToast:@"生成二进制文件错误"];
}else{
[self showToast:@"生成二进制文件成功"];
}
}
```
## Requirements
* **iOS 9.0** and up
* **Xcode 7.0** and up
## Installation
ScreenRecorderKit is not available through [CocoaPods](http://cocoapods.org) currently.
## Author
Huanghong, chinahuanghong@gmail.com
## Apps Integrated
* [夺镖体育](https://itunes.apple.com/cn/app/%E5%A4%BA%E9%95%96/id1294273600?mt=8)
## License
ScreenRecorderKit is available under the MIT license. See the LICENSE file for more info.
#
# Be sure to run `pod spec lint ScreenRecorderKit.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |spec|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#
spec.name = "ScreenRecorderKit"
spec.version = "0.0.2"
spec.summary = "ScreenRecorderKit is a delightful screen recorder framework based on ReplayeKit"
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
spec.description = <<-DESC
ScreenRecorderKit is a delightful screen recorder framework based on ReplayeKit. Hope you like it.
DESC
spec.homepage = "http://www.bbc6bae9.com/2019/03/11/hahah/"
# spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See https://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#
spec.license = "MIT"
# spec.license = { :type => "MIT", :file => "FILE_LICENSE" }
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#
spec.author = { "BBC6BAE9" => "chinahuanghong@gmail.com" }
# Or just: spec.author = "BBC6BAE9"
# spec.authors = { "BBC6BAE9" => "chinahuanghong@gmail.com" }
# spec.social_media_url = "https://twitter.com/BBC6BAE9"
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#
# spec.platform = :ios
# spec.platform = :ios, "5.0"
# When using multiple platforms
# spec.ios.deployment_target = "5.0"
# spec.osx.deployment_target = "10.7"
# spec.watchos.deployment_target = "2.0"
# spec.tvos.deployment_target = "9.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#
spec.source = { :git => "https://github.com/BBC6BAE9/ScreenRecorderKit.git", :tag => "#{spec.version}" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#
spec.source_files = "ScreenRecorderKit", "ScreenRecorderKit/**/*.{h,m}"
spec.exclude_files = "Classes/Exclude"
# spec.public_header_files = "Classes/**/*.h"
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#
# spec.resource = "icon.png"
# spec.resources = "Resources/*.png"
# spec.preserve_paths = "FilesToSave", "MoreFilesToSave"
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#
# spec.framework = "SomeFramework"
# spec.frameworks = "SomeFramework", "AnotherFramework"
# spec.library = "iconv"
# spec.libraries = "iconv", "xml2"
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.
# spec.requires_arc = true
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# spec.dependency "JSONKit", "~> 1.4"
end
//
// RPPreviewViewController+MovieURL.h
// hschefu-ios-staff
//
// Created by qiu on 2018/8/28.
// Copyright © 2018年 CodeTeam. All rights reserved.
//
#import <ReplayKit/ReplayKit.h>
@interface RPPreviewViewController (MovieURL)
/**
获取录屏的URL
*/
@property (nonatomic,strong) NSURL *movieURL;
@end
//
// RPPreviewViewController+MovieURL.m
// hschefu-ios-staff
//
// Created by qiu on 2018/8/28.
// Copyright © 2018年 CodeTeam. All rights reserved.
//
#import "RPPreviewViewController+MovieURL.h"
@implementation RPPreviewViewController (MovieURL)
@dynamic movieURL;
@end
//
// SRErrorHandle.h
// Duobiao
//
// Created by huang on 2019/5/25.
// Copyright © 2019 北京夺镖文化有限公司. All rights reserved.
//
#import "SRErrorInfo.h"
@interface SRErrorHandle : SRErrorInfo
- (instancetype)initWithError:(NSError *)error;
@end
//
// SRErrorHandle.m
// Duobiao
//
// Created by huang on 2019/5/25.
// Copyright © 2019 北京夺镖文化有限公司. All rights reserved.
//
#import "SRErrorHandle.h"
@implementation SRErrorHandle
- (id)initWithDic:(NSDictionary *)dic {
self = [super initWithDic:dic];
if (self) {
// if (code == 10042 || code == 10008 || code == 10012 || code == 10016) { // 未登录
//
// }else if(code == 10069){ // 账户被冻结
//
// }else if(code == 10004){
// // 服务器暂时无法响应,请稍后再试
// }
}
return self;
}
- (instancetype)initWithError:(NSError *)error {
if (self = [super init]) {
self.code = error.code;
if (error.code == -5807) { // -5807的错误是因为上一个extension没有关闭没办法重新打开,经试验,在applicationWillTerminate中退出也不起作用,主要精力放在避免崩溃,而不是放在Replaykit处理这个异常
self.msg = [NSString stringWithFormat:@"%@,请尝试重新启动手机解决", [error localizedDescription]];
}else{
self.msg = [error localizedDescription];
}
}
return self;
}
@end
//
// SRErrorInfo.h
// Duobiao
//
// Created by huang on 2019/5/25.
// Copyright © 2019 北京夺镖文化有限公司. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface SRErrorInfo : NSObject
{
NSInteger code;
NSString *msg;
BOOL isError;
}
/**
错误码
*/
@property (nonatomic, assign) NSInteger code;
/**
错误信息
*/
@property (nonatomic, copy) NSString *msg;
/**
是否有错误
*/
@property (nonatomic, assign) BOOL isError;
- (id)initWithDic:(NSDictionary *)dic;
- (instancetype)initWithDefault;
@end
NS_ASSUME_NONNULL_END
//
// SRErrorInfo.m
// Duobiao
//
// Created by huang on 2019/5/25.
// Copyright © 2019 北京夺镖文化有限公司. All rights reserved.
//
#import "SRErrorInfo.h"
@implementation SRErrorInfo
@synthesize code;
@synthesize msg;
@synthesize isError;
- (id)initWithDic:(NSDictionary *)dic
{
if (self = [super init]) {
self.code = [[dic objectForKey: @"error_code"] integerValue];
self.msg = [dic objectForKey: @"error_msg"];
if (self.code == 0) {
isError = NO;
}
else{
isError = YES;
}
}
return self;
}
- (instancetype)initWithDefault
{
if (self = [super init]) {
self.msg = @"一般错误";
self.code = 1;
}
return self;
}
@end
//
// ScreenRecordManager.h
// 录制屏幕框架
//
// Created by huang on 2019/5/24.
// Copyright © 2019 huang. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "SRErrorHandle.h"
#import "SRErrorInfo.h"
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
// 录屏状态
typedef NS_ENUM(NSInteger, RecState) {
RecState_Rec = 0,
RecState_Stop = 1
};
@protocol ScreenRecordDelegate <NSObject>
@optional
/**
保存到相册的代理方法
@param image 路径,好像没什么用
@param error 错误信息
@param contextInfo 额外信息
*/
- (void)savedPhotoImage:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
/**
生成视频的二进制文件
@param data 二进制数据
@param isError 是否有错误
*/
- (void)savedVideoData:(NSData*)data didFinishSavingWithError:(BOOL)isError;
/**
录制状态变化的代理方法
@param state 状态
@param error 错误信息
*/
-(void)recStateDidChange:(RecState)state withError:(NSError *__nullable)error;
@end
typedef void(^srerrorinfo)(SRErrorHandle *error);
@interface ScreenRecordManager : NSObject
+ (instancetype)shareManager;
@property(nonatomic,weak)id<ScreenRecordDelegate> screenRecordDelegate;
/**
是否正在录制中
*/
@property(nonatomic, assign) BOOL isRecording;
/**
录制屏幕
@param suc 成功回调
@param errorInfo 错误信息
*/
- (void)screenRecSuc:(void (^)(void))suc failure:(srerrorinfo)errorInfo;
/**
停止录制屏幕
@param suc 成功回调
@param errorInfo 错误信息
*/
- (void)stopRecSuc:(void (^)(void))suc failure:(srerrorinfo)errorInfo;
@end
NS_ASSUME_NONNULL_END
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment