1

我包括“可达性/可达性.m”

AppDelegate.h

#import <UIKit/UIKit.h>
#import "Reachability/Reachability.m"

@class ...;

@interface ... : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    ... *viewController;
    Reachability *hostReach;
    NetworkStatus netStatus;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic) NetworkStatus netStatus;
-(void)updateInterfaceWithReachability: (Reachability*) curReach;

@end


AppDelegate.m


#import "AppDelegate.h"
#import "ViewController.h"

@implementation ...

@synthesize window=_window;
@synthesize navigationController=_navigationController;
@synthesize netStatus;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
    hostReach = [[Reachability reachabilityWithHostName:@"www.apple.com"]retain];
    [hostReach startNotifier];
    [self updateInterfaceWithReachability:hostReach];


    // Set the view controller as the window's root view controller and display.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

我得到一个错误

ld: duplicate symbol _OBJC_IVAR_$_Reachability.localWiFiRef in /Users/../Documents/../build/.. .build/Debug-iphonesimulator/.. .build/Objects-normal/i386/..ViewController.o and /Users/../Documents/../build/.. .build/Debug-iphonesimulator/.. .build/Objects-normal/i386/..AppDelegate.o

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

如何解决这个问题呢?它可能与什么有关?

4

4 回答 4

5

我遇到了同样的问题,因为我正在使用的一个第三方库(libPusher)已经包含了 Reachability。

由于该库是预编译的,我不知道该怎么做,但只添加Reachability.h到项目(而不是Reachability.m)有效。这允许我导入它并使用该类,但我没有重复符号问题。

于 2012-10-25T05:06:23.870 回答
2

您只导入头文件。做,

#import "Reachability/Reachability.h"
于 2011-06-29T12:55:10.653 回答
2

您必须确保您的项目文件夹包含一个 Reachability.h 和一个 Reachability.m 文件,ASIHTTPRequest 库中包含这两个文件,因此添加 Reachability 库时出现重复符号错误。删除重复文件后进行干净的构建

于 2012-04-26T14:27:20.210 回答
0
  1. 从项目中删除reachability.m 的引用。
  2. 添加您想要的框架或文件(创建此问题)。
  3. 清理并构建项目

它对我有用。

当我尝试在项目中添加框架时,出现了这个重复的问题。

于 2015-12-21T13:12:42.197 回答