【问题标题】:asiHttpRequest under iOS5iOS5下的asiHttpRequest
【发布时间】:2012-01-02 10:55:32
【问题描述】:

我成功地使用 AsiHttpRequest 库在我的应用程序中建立 url 连接。但是,我升级到 iOS5 并且 Reachability.m 文件在以下功能上报告了一些错误(4):

static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) {

    #pragma unused (target, flags)
    NSCAssert(info, @"info was NULL in ReachabilityCallback");
    NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was the wrong class in ReachabilityCallback");


    // Post a notification to notify the client that the network reachability changed.
    [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: (Reachability *) info];


} // ReachabilityCallback()


- (BOOL) startNotifier {

    SCNetworkReachabilityContext    context = {0, self, NULL, NULL, NULL};

    if(SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context)) {

        if(SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {

            return YES;

        }

    }

    return NO;

} // startNotifier

1sr 错误:在 NSCAssert 行中,“C 指针类型 'void' 到 Objective-C 指针类型 NSObject 的转换需要桥接转换”。为什么会发生以及如何解决?

回答:您可以为每个文件禁用 ARC。转到项目的构建设置并在所有 ASIHTTPRequest 文件上设置 -fno-objc-arc 标志(双击以编辑文本)。然后,您必须删除 ASIAuthenticationDialog 以及对它的任何仍然产生错误的引用。它对我有用。

【问题讨论】:

  • 我的回答主要是帮助有类似问题的人。如果您投票-1,至少请解释原因。谢谢

标签: objective-c cocoa-touch ios5 asihttprequest


【解决方案1】:

编辑:我现在记得,是的,问题是 ARC。但是您可以通过在 Build Phases >> Compile Sources 中设置以下编译器标志来排除在 ARC 下编译的文件:-fno-objc-arc。如果您选择所有 ASIHTTPRequest 文件并双击,则可以一举为所有文件设置标志。

原帖:

我已经使用 ASIHTTPRequest 几个星期了,我记得在某处读过一篇关于可达性问题的帖子,我只是不记得它到底是什么。

无论如何,这就是我的 Reachability.m 中的那些行的样子:

//Start listening for reachability notifications on the current run loop
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) {

#pragma unused (target, flags)
NSCAssert(info, @"info was NULL in ReachabilityCallback");
NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was the wrong class in ReachabilityCallback");

//We're on the main RunLoop, so an NSAutoreleasePool is not necessary, but is added defensively
// in case someone uses the Reachablity object in a different thread.
NSAutoreleasePool* pool = [NSAutoreleasePool new];

// Post a notification to notify the client that the network reachability changed.
[[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification 
                                                    object: (Reachability *) info];

[pool release];

} // ReachabilityCallback()


- (BOOL) startNotifier {

    SCNetworkReachabilityContext    context = {0, self, NULL, NULL, NULL};

    if(SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context)) {

        if(SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {

            return YES;

        }

    }

    return NO;

} // startNotifier

【讨论】:

  • 与我使用的代码相同,但可以在 iOS5 上使用。问题来自 ARC。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-21
  • 1970-01-01
相关资源
最近更新 更多