我将我的网络功能迁移AFNetworking到了AFNetworking v2,而不是AFHttpClient我AFHTTPRequestOperationManager用来支持iOS6.
我的问题是,虽然AFHttpClient有使用.取消待处理请求的功能
- (void)cancelAllHTTPOperationsWithMethod:(NSString *)method path:(NSString *)path;
Run Code Online (Sandbox Code Playgroud)
方法,在AFHTTPRequestOperationManager没有这种明显的方法.
我到目前为止所做的是AFHTTPRequestOperationManager继承和声明一个iVar
AFHTTPRequestOperation *_currentRequest;
Run Code Online (Sandbox Code Playgroud)
当我提出请求时,代码就是这样的
- (void)GetSomething:(NSInteger)ID success:(void (^)(MyResponse *))success failure:(void (^)(NSError *))failure
{
_currentRequest = [self GET:@"api/something" parameters:@{@"ID": [NSNumber numberWithInteger:ID]} success:^(AFHTTPRequestOperation *operation, id responseObject) {
MyResponse *response = [MyResponse responseFromDictionary:responseObject];
success(response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failure(error);
}];
}
Run Code Online (Sandbox Code Playgroud)
我有一个
- (void)cancelCurrentRequest;
Run Code Online (Sandbox Code Playgroud)
所有这些的方法都是
- (void)cancelCurrentRequest
{
if(_currentRequest) {
[_currentRequest cancel]; _currentRequest = nil;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我不认为这是一个好的做法,当调用该方法时,我得到了 …
在此之前,我已经阅读了这个和这个问题,以解决下面的问题,然后再询问.
我的问题是,当accessToken过期时(或者因为过期日期过去,或者通过从我的Facebook的App Center中删除应用程序而手动操作),以下代码:
if ([[FBSession activeSession] isOpen]) {
//do something
}
else {
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if(FB_ISSESSIONOPENWITHSTATE(status)) {
//do something
}
}
}];
}
Run Code Online (Sandbox Code Playgroud)
在FBSession.activeSession打开的情况下进入else块,但是当执行'do something'时,accessToken无效,因此请求获得错误:HTTP状态代码:400.当我尝试立即执行整个过程两次时,FBSession请求权限(UIAlertView for iOS6集成了facebook,Facebook App或Safari网站),其余的运行顺畅.
我担心的是为什么我必须做两次才能正常工作以及为什么Facebook SDK第一次无法检测到activeSession和accessToken无效.
谢谢大家!
我正在我的应用程序中录制音频,包括前景和后台.我还处理AVAudioSessionInterruptionNotification以在中断开始时停止录制并在结束时再次开始.虽然在前台它按预期工作,当应用程序在后台录制并且我接到一个呼叫时,它不会在呼叫结束后再次开始录制.我的代码如下:
- (void)p_handleAudioSessionInterruptionNotification:(NSNotification *)notification
{
NSUInteger interruptionType = [[[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
if (interruptionType == AVAudioSessionInterruptionTypeBegan) {
if (self.isRecording && !self.interruptedWhileRecording) {
[self.recorder stop];
self.interruptedWhileRecording = YES;
return;
}
}
if (interruptionType == AVAudioSessionInterruptionTypeEnded) {
if (self.interruptedWhileRecording) {
NSError *error = nil;
[[AVAudioSession sharedInstance] setActive:YES error:&error];
NSDictionary *settings = @{
AVEncoderAudioQualityKey: @(AVAudioQualityMax),
AVSampleRateKey: @8000,
AVFormatIDKey: @(kAudioFormatLinearPCM),
AVNumberOfChannelsKey: @1,
AVLinearPCMBitDepthKey: @16,
AVLinearPCMIsBigEndianKey: @NO,
AVLinearPCMIsFloatKey: @NO
};
_recorder = [[AVAudioRecorder alloc] initWithURL:fileURL settings:settings error:nil];
[self.recorder record];
self.interruptedWhileRecording = NO;
return;
}
} …Run Code Online (Sandbox Code Playgroud) 有没有办法可以将 Visual Studio Code 设置为 Mac 上 Sourcetree 中的默认差异/合并工具?
在问一个单独的问题之前,我已经做了很多关于它的谷歌搜索并在已经存在的stackoverflow 问题中添加了注释.
我在我的服务器中有一个SignalR Hub(试过v.1.1.3和2.0.0-rc),代码如下:
[HubName("TestHub")]
public class TestHub : Hub
{
[Authorize]
public void TestMethod(string test)
{
//some stuff here
Clients.Caller.NotifyOnTestCompleted();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我删除Authorize属性,问题仍然存在.
在我的iOS客户端中,我尝试使用以下代码调用它:
SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:_baseURL];
SRHubProxy *hubProxy = [hubConnection createHubProxy:@"TestHub"];
[hubProxy on:@"NotifyOnTestCompleted" perform:self selector:@selector(stopConnection)];
hubConnection.started = ^{
[hubProxy invoke:@"TestMethod" withArgs:@[@"test"]];
};
//received, error handling
[hubConnection start];
Run Code Online (Sandbox Code Playgroud)
当应用程序启动时,用户未登录,并且没有打开SignalR连接.用户通过调用服务器中的登录服务来登录,该服务使用WebSecurity.Login方法.如果登录服务返回成功,则我对SignalR Hub进行上述调用,我得到服务器错误500,其描述为"ConnectionId的格式不正确".
完整的服务器堆栈跟踪如下:
Exception information:
Exception type: InvalidOperationException
Exception message: The ConnectionId is in the incorrect format.
at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken)
at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context)
at …Run Code Online (Sandbox Code Playgroud)