Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
OffcnIMSDKiOS
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
opensource
OffcnIMSDKiOS
Commits
9220604b
Commit
9220604b
authored
Aug 25, 2020
by
zhangyunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传类型区分
parent
11cf04da
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
14 deletions
+136
-14
OffcnIMSDKiOS.h
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSDKiOS.h
+2
-2
OffcnIMSDKiOS.m
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSDKiOS.m
+134
-12
No files found.
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSDKiOS.h
View file @
9220604b
//
//
...
@@ -60,7 +60,7 @@ typedef void(^OffcnSDKReachabilityStatusCallBack)(OffcnSDKReachabilityStatus sta
...
@@ -60,7 +60,7 @@ typedef void(^OffcnSDKReachabilityStatusCallBack)(OffcnSDKReachabilityStatus sta
/// @param msg_toID 接收人ID
/// @param msg_toID 接收人ID
/// @param msg_type 发送消息类型
/// @param msg_type 发送消息类型
/// @param text 文本
/// @param text 文本
/// @param filePath 图片/音频/视频/文件路径
/// @param filePath 图片/音频
(语音消息格式,只能是aac格式)
/视频/文件路径
/// @param finished 结果回调
/// @param finished 结果回调
-
(
void
)
sendMsgWithMsg_fromID
:(
NSString
*
)
msg_fromID
msg_toID
:(
NSString
*
)
msg_toID
msg_type
:(
OffcnSDKMsgType
)
msg_type
text
:(
NSString
*
)
text
filePath
:(
NSString
*
)
filePath
Finished
:(
void
(
^
)(
BOOL
success
,
id
response
,
NSString
*
errorMessage
))
finished
;
-
(
void
)
sendMsgWithMsg_fromID
:(
NSString
*
)
msg_fromID
msg_toID
:(
NSString
*
)
msg_toID
msg_type
:(
OffcnSDKMsgType
)
msg_type
text
:(
NSString
*
)
text
filePath
:(
NSString
*
)
filePath
Finished
:(
void
(
^
)(
BOOL
success
,
id
response
,
NSString
*
errorMessage
))
finished
;
...
...
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSDKiOS.m
View file @
9220604b
//
//
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
#import "SDGeneralTool.h"
#import "SDGeneralTool.h"
#import "DataSafe.h"
#import "DataSafe.h"
#import "NSString+MD5.h"
#import "NSString+MD5.h"
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface
OffcnIMSDKiOS
()
@interface
OffcnIMSDKiOS
()
...
@@ -109,6 +111,7 @@ static OffcnIMSDKiOS *liveTelecastSDK;
...
@@ -109,6 +111,7 @@ static OffcnIMSDKiOS *liveTelecastSDK;
#pragma mark - 操作事件
#pragma mark - 操作事件
-
(
void
)
sendMsgWithMsg_fromID
:
(
NSString
*
)
msg_fromID
msg_toID
:
(
NSString
*
)
msg_toID
msg_type
:
(
OffcnSDKMsgType
)
msg_type
text
:
(
NSString
*
)
text
filePath
:
(
NSString
*
)
filePath
Finished
:
(
void
(
^
)(
BOOL
success
,
id
response
,
NSString
*
errorMessage
))
finished
{
-
(
void
)
sendMsgWithMsg_fromID
:
(
NSString
*
)
msg_fromID
msg_toID
:
(
NSString
*
)
msg_toID
msg_type
:
(
OffcnSDKMsgType
)
msg_type
text
:
(
NSString
*
)
text
filePath
:
(
NSString
*
)
filePath
Finished
:
(
void
(
^
)(
BOOL
success
,
id
response
,
NSString
*
errorMessage
))
finished
{
KWeakSelf
//发送消息
//发送消息
if
(
msg_type
==
OffcnSDKMsgTypeText
)
{
if
(
msg_type
==
OffcnSDKMsgTypeText
)
{
if
(
!
text
||
!
text
.
length
)
{
if
(
!
text
||
!
text
.
length
)
{
...
@@ -131,33 +134,63 @@ static OffcnIMSDKiOS *liveTelecastSDK;
...
@@ -131,33 +134,63 @@ static OffcnIMSDKiOS *liveTelecastSDK;
if
(
response
)
{
if
(
response
)
{
urlStr
=
[
NSString
stringWithFormat
:
@"%@"
,
response
];
urlStr
=
[
NSString
stringWithFormat
:
@"%@"
,
response
];
}
}
NSString
*
md5Str
=
[
urlStr
md5Encrypt
];
NSMutableDictionary
*
dataDic
=
[
NSMutableDictionary
dictionary
];
NSMutableDictionary
*
dataDic
=
[
NSMutableDictionary
dictionary
];
if
(
msg_type
==
OffcnSDKMsgTypePicture
)
{
if
(
msg_type
==
OffcnSDKMsgTypePicture
)
{
NSString
*
nameStr
=
[
NSString
stringWithFormat
:
@"%@%@"
,
msg_toID
,[
SDGeneralTool
getNowSSSTimeTimestamp
]];
NSString
*
nameStr
=
[
NSString
stringWithFormat
:
@"%@_%@"
,
msg_toID
,[
SDGeneralTool
getNowSSSTimeTimestamp
]];
NSString
*
md5Str
=
[
urlStr
md5Encrypt
];
NSString
*
extStr
=
[
filePath
pathExtension
];
UIImage
*
image1
=
[
UIImage
imageWithContentsOfFile
:
filePath
];
CGSize
imgSize
=
image1
.
size
;
long
long
folderSize
=
[
weakSelf
fileSizeAtPath
:
filePath
];
[
dataDic
setObjectOnSafe
:
urlStr
forKey
:
@"url"
];
[
dataDic
setObjectOnSafe
:
urlStr
forKey
:
@"url"
];
[
dataDic
setObjectOnSafe
:
nameStr
forKey
:
@"name"
];
[
dataDic
setObjectOnSafe
:
nameStr
forKey
:
@"name"
];
[
dataDic
setObjectOnSafe
:
md5Str
forKey
:
@"md5"
];
[
dataDic
setObjectOnSafe
:
md5Str
forKey
:
@"md5"
];
[
dataDic
setObjectOnSafe
:
@""
forKey
:
@"thumb_url"
];
[
dataDic
setObjectOnSafe
:
@""
forKey
:
@"thumb_url"
];
[
dataDic
setObjectOnSafe
:
extStr
forKey
:
@"ext"
];
[
dataDic
setObjectOnSafe
:
@""
forKey
:
@"ext"
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithFloat
:
imgSize
.
width
]
forKey
:
@"w"
];
[
dataDic
setObjectOnSafe
:
@""
forKey
:
@"w"
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithFloat
:
imgSize
.
height
]
forKey
:
@"h"
];
[
dataDic
setObjectOnSafe
:
@""
forKey
:
@"h"
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithLongLong
:
folderSize
]
forKey
:
@"size"
];
[
dataDic
setObjectOnSafe
:
@""
forKey
:
@"size"
];
}
else
if
(
msg_type
==
OffcnSDKMsgTypeAudio
){
}
else
if
(
msg_type
==
OffcnSDKMsgTypeAudio
){
NSInteger
dur
=
(
NSInteger
)[
weakSelf
audioDurationFromUrl
:
filePath
];
NSString
*
extStr
=
[
filePath
pathExtension
];
long
long
folderSize
=
[
weakSelf
fileSizeAtPath
:
filePath
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithInteger
:
dur
]
forKey
:
@"dur"
];
[
dataDic
setObjectOnSafe
:
md5Str
forKey
:
@"md5"
];
[
dataDic
setObjectOnSafe
:
urlStr
forKey
:
@"url"
];
[
dataDic
setObjectOnSafe
:
extStr
forKey
:
@"ext"
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithLongLong
:
folderSize
]
forKey
:
@"size"
];
}
else
if
(
msg_type
==
OffcnSDKMsgTypeVideo
){
}
else
if
(
msg_type
==
OffcnSDKMsgTypeVideo
){
NSDictionary
*
dic
=
[
weakSelf
getVideoInfoWithSourcePath
:
filePath
];
NSInteger
dur
=
[[
dic
objectForKeyOnSafe
:
@"duration"
]
integerValue
];
NSString
*
extStr
=
[
filePath
pathExtension
];
long
long
fileSize
=
[[
dic
objectForKeyOnSafe
:
@"fileSize"
]
longLongValue
];
CGSize
size
=
[
weakSelf
getVideoSizeWithSourcePath
:
filePath
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithInteger
:
dur
]
forKey
:
@"dur"
];
[
dataDic
setObjectOnSafe
:
md5Str
forKey
:
@"md5"
];
[
dataDic
setObjectOnSafe
:
urlStr
forKey
:
@"url"
];
[
dataDic
setObjectOnSafe
:
@""
forKey
:
@"cover_url"
];
[
dataDic
setObjectOnSafe
:
extStr
forKey
:
@"ext"
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithLongLong
:
fileSize
]
forKey
:
@"size"
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithFloat
:
size
.
width
]
forKey
:
@"w"
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithFloat
:
size
.
height
]
forKey
:
@"h"
];
}
else
if
(
msg_type
==
OffcnSDKMsgTypeFile
){
}
else
if
(
msg_type
==
OffcnSDKMsgTypeFile
){
NSString
*
nameStr
=
[
NSString
stringWithFormat
:
@"%@_%@"
,
msg_toID
,[
SDGeneralTool
getNowSSSTimeTimestamp
]];
NSString
*
extStr
=
[
filePath
pathExtension
];
long
long
folderSize
=
[
weakSelf
fileSizeAtPath
:
filePath
];
[
dataDic
setObjectOnSafe
:
nameStr
forKey
:
@"name"
];
[
dataDic
setObjectOnSafe
:
md5Str
forKey
:
@"md5"
];
[
dataDic
setObjectOnSafe
:
urlStr
forKey
:
@"url"
];
[
dataDic
setObjectOnSafe
:
extStr
forKey
:
@"ext"
];
[
dataDic
setObjectOnSafe
:[
NSNumber
numberWithLongLong
:
folderSize
]
forKey
:
@"size"
];
}
}
[
OffcnNetworkExecutor
requestSendMsgWithMsg_fromID
:
msg_fromID
msg_toID
:
msg_toID
msg_type
:
msg_type
msg
:
dataDic
Finished
:^
(
BOOL
success
,
id
response
,
BaseResponse
*
baseResponse
)
{
[
OffcnNetworkExecutor
requestSendMsgWithMsg_fromID
:
msg_fromID
msg_toID
:
msg_toID
msg_type
:
msg_type
msg
:
dataDic
Finished
:^
(
BOOL
success
,
id
response
,
BaseResponse
*
baseResponse
)
{
finished
(
success
,
nil
,
baseResponse
.
errorMessage
);
finished
(
success
,
nil
,
baseResponse
.
errorMessage
);
...
@@ -169,7 +202,96 @@ static OffcnIMSDKiOS *liveTelecastSDK;
...
@@ -169,7 +202,96 @@ static OffcnIMSDKiOS *liveTelecastSDK;
}
}
}
}
//单个文件的大小
-
(
long
long
)
fileSizeAtPath
:
(
NSString
*
)
filePath
{
NSFileManager
*
manager
=
[
NSFileManager
defaultManager
];
if
([
manager
fileExistsAtPath
:
filePath
]){
return
[[
manager
attributesOfItemAtPath
:
filePath
error
:
nil
]
fileSize
];
}
return
0
;
}
//遍历文件夹获得文件夹大小,返回字节
-
(
long
long
)
folderSizeAtPath
:
(
NSString
*
)
folderPath
{
NSFileManager
*
manager
=
[
NSFileManager
defaultManager
];
if
(
!
[
manager
fileExistsAtPath
:
folderPath
])
return
0
;
NSString
*
fileName
=
[
folderPath
copy
];
long
long
folderSize
=
0
;
BOOL
isdir
;
[
manager
fileExistsAtPath
:
fileName
isDirectory
:
&
isdir
];
if
(
isdir
!=
YES
)
{
return
[
self
fileSizeAtPath
:
fileName
];
}
else
{
NSArray
*
items
=
[
manager
contentsOfDirectoryAtPath
:
fileName
error
:
nil
];
for
(
int
i
=
0
;
i
<
items
.
count
;
i
++
)
{
BOOL
subisdir
;
NSString
*
fileAbsolutePath
=
[
fileName
stringByAppendingPathComponent
:
items
[
i
]];
[
manager
fileExistsAtPath
:
fileAbsolutePath
isDirectory
:
&
subisdir
];
if
(
subisdir
==
YES
)
{
folderSize
+=
[
self
folderSizeAtPath
:
fileAbsolutePath
];
//文件夹就递归计算
}
else
{
folderSize
+=
[
self
fileSizeAtPath
:
fileAbsolutePath
];
//文件直接计算
}
}
}
return
folderSize
;
//folderSize/(1024*1024)递归时候会运算两次出错,所以返回字节。在外面再计算
}
-
(
NSString
*
)
localFileSizeTextWithFolderSize
:
(
long
long
)
size
{
// NSString *sizeText = @"0";
// if (size >= pow(10, 9)) { // size >= 1GB
// sizeText = [NSString stringWithFormat:@"%.2fGB", size / pow(10, 9)];
// } else if (size >= pow(10, 6)) { // 1GB > size >= 1MB
// sizeText = [NSString stringWithFormat:@"%.2fMB", size / pow(10, 6)];
// } else if (size >= pow(10, 3)) { // 1MB > size >= 1KB
// sizeText = [NSString stringWithFormat:@"%.2fKB", size / pow(10, 3)];
// } else { // 1KB > size
// sizeText = [NSString stringWithFormat:@"%lldB", size];
// }
return
[
NSString
stringWithFormat
:
@"%lld"
,
size
];
}
//音频
-
(
NSTimeInterval
)
audioDurationFromUrl
:
(
NSString
*
)
url
{
AVURLAsset
*
audioAsset
=
nil
;
NSDictionary
*
dic
=
@{
AVURLAssetPreferPreciseDurationAndTimingKey
:
@
(
YES
)};
if
([
url
hasPrefix
:
@"http://"
]
||
[
url
hasPrefix
:
@"https://"
])
{
audioAsset
=
[
AVURLAsset
URLAssetWithURL
:[
NSURL
URLWithString
:
url
]
options
:
dic
];
}
else
{
audioAsset
=
[
AVURLAsset
URLAssetWithURL
:[
NSURL
fileURLWithPath
:
url
]
options
:
dic
];
}
CMTime
audioDuration
=
audioAsset
.
duration
;
float
audioDurationSeconds
=
CMTimeGetSeconds
(
audioDuration
);
return
audioDurationSeconds
;
}
//视频
-
(
NSDictionary
*
)
getVideoInfoWithSourcePath
:
(
NSString
*
)
path
{
AVURLAsset
*
asset
=
[
AVURLAsset
assetWithURL
:[
NSURL
fileURLWithPath
:
path
]];
CMTime
time
=
[
asset
duration
];
int
seconds
=
ceil
(
time
.
value
/
time
.
timescale
);
long
long
fileSize
=
[[
NSFileManager
defaultManager
]
attributesOfItemAtPath
:
path
error
:
nil
].
fileSize
;
return
@{
@"fileSize"
:
@
(
fileSize
),
@"duration"
:
@
(
seconds
)};
}
-
(
CGSize
)
getVideoSizeWithSourcePath
:
(
NSString
*
)
path
{
AVURLAsset
*
asset
=
[
AVURLAsset
assetWithURL
:[
NSURL
fileURLWithPath
:
path
]];
NSArray
*
array
=
asset
.
tracks
;
CGSize
videoSize
=
CGSizeZero
;
for
(
AVAssetTrack
*
track
in
array
){
if
([
track
.
mediaType
isEqualToString
:
AVMediaTypeVideo
]){
videoSize
=
track
.
naturalSize
;
}
}
return
videoSize
;
}
-
(
void
)
dealloc
{
-
(
void
)
dealloc
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment