Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit c904c4f4
由
cgx
编写于
2022-11-03 11:53:07 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
完善请求头
1 个父辈
4a451cba
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
7 行删除
DreamSleep/DreamSleep/Basement/Category/NSString+Extras.h
DreamSleep/DreamSleep/Basement/Category/NSString+Extras.m
DreamSleep/DreamSleep/Basement/Network/DSNetworkTool.m
DreamSleep/DreamSleep/Basement/Category/NSString+Extras.h
查看文件 @
c904c4f
...
...
@@ -43,6 +43,10 @@ NS_ASSUME_NONNULL_BEGIN
/// @param width width
/// @param attributes attributes
-
(
NSArray
*
)
getLinesArrayOfStringWidth
:(
CGFloat
)
width
attributes
:(
NSDictionary
*
)
attributes
;
/// 字典转json字符串并且转码
/// @param dict dict
+
(
NSString
*
)
convertToJsonStr
:(
NSDictionary
*
)
dict
;
@end
NS_ASSUME_NONNULL_END
DreamSleep/DreamSleep/Basement/Category/NSString+Extras.m
查看文件 @
c904c4f
...
...
@@ -91,4 +91,30 @@
return
(
NSArray
*
)
linesArray
;
}
+
(
NSString
*
)
convertToJsonStr
:(
NSDictionary
*
)
dict
{
NSError
*
error
;
NSData
*
jsonData
=
[
NSJSONSerialization
dataWithJSONObject
:
dict
options
:
NSJSONWritingPrettyPrinted
error
:&
error
];
NSString
*
jsonString
=
@""
;
if
(
!
jsonData
)
{
NSLog
(
@"%@"
,
error
);
}
else
{
jsonString
=
[[
NSString
alloc
]
initWithData
:
jsonData
encoding
:
NSUTF8StringEncoding
];
}
NSMutableString
*
mutStr
=
[
NSMutableString
stringWithString
:
jsonString
];
NSRange
range
=
{
0
,
jsonString
.
length
};
[
mutStr
replaceOccurrencesOfString
:
@" "
withString
:
@""
options
:
NSLiteralSearch
range
:
range
];
NSRange
range2
=
{
0
,
mutStr
.
length
};
[
mutStr
replaceOccurrencesOfString
:
@" "
withString
:
@""
options
:
NSLiteralSearch
range
:
range2
];
NSString
*
jsonStr
=
[
mutStr
stringByAddingPercentEncodingWithAllowedCharacters
:[
NSCharacterSet
URLQueryAllowedCharacterSet
]];
return
jsonStr
.
copy
;
}
@end
DreamSleep/DreamSleep/Basement/Network/DSNetworkTool.m
查看文件 @
c904c4f
...
...
@@ -57,14 +57,16 @@ NSString * const NetworkUnableError = @"网络不给力,请检查您的网络
// 请求头自定义字段sid
[
request
addValue
:[
LoginUtils
getSid
]
forHTTPHeaderField
:
@"sid"
];
// 基础参数
NSMutableDictionary
*
appInfos
=
[
NSMutableDictionary
dictionary
];
NSDictionary
*
infoDictionary
=
[[
NSBundle
mainBundle
]
infoDictionary
];
[
request
addValue
:
infoDictionary
[
@"CFBundleDisplayName"
]
forHTTPHeaderField
:
@"appName"
];
[
request
addValue
:
@"AppStore"
forHTTPHeaderField
:
@"promoterId"
];
[
request
addValue
:
infoDictionary
[
@"CFBundleShortVersionString"
]
forHTTPHeaderField
:
@"version"
];
[
request
addValue
:[
UIDevice
currentDevice
].
systemVersion
forHTTPHeaderField
:
@"versionCode"
];
[
request
addValue
:[
UIDevice
currentDevice
].
systemName
forHTTPHeaderField
:
@"os"
];
[
request
addValue
:[[
NSBundle
mainBundle
]
bundleIdentifier
]
forHTTPHeaderField
:
@"packageName"
];
[
appInfos
setValue
:
infoDictionary
[
@"CFBundleDisplayName"
]
forKey
:
@"appName"
];
[
appInfos
setValue
:
@"AppStore"
forKey
:
@"promoterId"
];
[
appInfos
setValue
:
infoDictionary
[
@"CFBundleShortVersionString"
]
forKey
:
@"version"
];
[
appInfos
setValue
:[
UIDevice
currentDevice
].
systemVersion
forKey
:
@"versionCode"
];
[
appInfos
setValue
:[
UIDevice
currentDevice
].
systemName
forKey
:
@"os"
];
[
appInfos
setValue
:[[
NSBundle
mainBundle
]
bundleIdentifier
]
forKey
:
@"packageName"
];
[
request
addValue
:[
NSString
convertToJsonStr
:
appInfos
]
forHTTPHeaderField
:
@"appversion"
];
NSURLSessionDataTask
*
dataTask
=
[[
DSNetworkTool
sharedManager
]
dataTaskWithRequest
:
request
uploadProgress
:
nil
downloadProgress
:
nil
completionHandler
:^
(
NSURLResponse
*
_Nonnull
response
,
id
_Nullable
responseObject
,
NSError
*
_Nullable
error
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[[
UIApplication
sharedApplication
]
setNetworkActivityIndicatorVisible
:
NO
];
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论