我正在努力学习NSURLSession在iOS 7 SDK中引入的课程,而且我遇到了困难,我需要用方法调用我的REST APIPUT.
我已经实现了GET和POST方法,使用这个工作正常:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPMethod:httpMethod]; // GET/POST works, PUT does not
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error){
// do something here
( ... )
} else {
// process error
( ... )
}
}];
[postDataTask resume];
Run Code Online (Sandbox Code Playgroud)
不幸的是,设置httpMethod到PUT似乎并没有工作(它作为行为GET).从cURL控制台调用*url的内容工作正常 - 因此API的路径是可以的.
如何PUT …
我有跟随,简单的表
Item (id, name, date, fixed_position)
(1, 'first entry', '2016-03-09 09:00:00', NULL)
(2, 'second entry', '2016-03-09 04:00:00', 1)
(3, 'third entry', '2016-03-09 05:00:00', NULL)
(4, 'fourth entry', '2016-03-09 19:00:00', NULL)
(5, 'fifth entry', '2016-03-09 13:00:00', 4)
(6, 'sixth entry', '2016-03-09 21:00:00', 2)
Run Code Online (Sandbox Code Playgroud)
物品的数量不固定,实际上可以在~100到~1000之间变化.
我想要实现的是执行查询以返回按date字段排序的项目集合,该fixed_position字段考虑字段,其代表类似"固定"结果到特定位置的内容.如果fixed_position给定条目不为NULL,则结果应固定到第n个位置,如果fixed_position为NULL,ORDER BY则应优先.
期望的查询输出更明亮的解释:
(2, 'second entry', '2016-03-09 04:00:00', 1) // pinned to 1-st position
(6, 'sixth entry', '2016-03-09 21:00:00', 2) // pinned to 2-nd position
(3, 'third …Run Code Online (Sandbox Code Playgroud) 我有AVAudioPlayer在后台播放一些MP3.AVAudioPlayer是跨应用程序共享的单例实例.是否可以一次检测正在播放的MP3的当前文件名?我在委托中看不到任何方法,有持续时间,currentTime但也没有文件名或类似的东西.
我认为如果这种方法失败的另一件事是读取MP3标签并从中获取音轨名称 - 是否可以使用AVAudioPlayer?
提前致谢!