小编ozz*_*tto的帖子

AFNetworking 2:如何取消AFHTTPRequestOperationManager请求?

我将我的网络功能迁移AFNetworking到了AFNetworking v2,而不是AFHttpClientAFHTTPRequestOperationManager用来支持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)

现在,我不认为这是一个好的做法,当调用该方法时,我得到了 …

afnetworking-2

37
推荐指数
1
解决办法
2万
查看次数

使用Facebook iOS 3.1.1 SDK中的FBSession openActiveSessionWithReadPermissions处理无效的accessToken

在此之前,我已经阅读了这个这个问题,以解决下面的问题,然后再询问.

我的问题是,当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无效.

谢谢大家!

facebook objective-c ios facebook-ios-sdk

15
推荐指数
1
解决办法
1万
查看次数

音频会话中断结束后,AVAudioRecorder无法在后台录制

我正在我的应用程序中录制音频,包括前景和后台.我还处理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)

xcode objective-c avaudiorecorder ios avaudiosession

10
推荐指数
2
解决办法
3977
查看次数

Visual Studio Code for Mac 作为 Sourcetree 中的差异/合并工具

有没有办法可以将 Visual Studio Code 设置为 Mac 上 Sourcetree 中的默认差异/合并工具?

git macos atlassian-sourcetree visual-studio-code

9
推荐指数
3
解决办法
6231
查看次数

SignalR服务器错误"ConnectionId的格式不正确." 使用SignalR-ObjC库

在问一个单独的问题之前,我已经做了很多关于它的谷歌搜索并在已经存在的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)

asp.net xcode objective-c signalr visual-studio-2012

5
推荐指数
1
解决办法
2022
查看次数