Ios 将ObjC项目与SalesForce SDK桥接会由于无法在SF SDK中找到类别而导致崩溃

Ios 将ObjC项目与SalesForce SDK桥接会由于无法在SF SDK中找到类别而导致崩溃,ios,objective-c,swift,salesforce,bridging-header,Ios,Objective C,Swift,Salesforce,Bridging Header,我有一个名为Core.proj的iOS项目,包括SalesForce SDK,它是用Objective-C编写的。该项目使用SF SDK并将二进制文件链接到SF库。它做了很多事情来帮助我管理SF的实现。它包含在我的所有其他Obj-C项目中,并且在其中工作得非常好 这是我第一次在Swift(2.1)中使用这个项目。我正在使用iOS9和Xcode 7.1.1。我在Swift项目中添加了Core.xcodeproj。然后我创建了一个ObjC文件。然后,Xcode询问我是否要创建桥接头。我愿意。我已经创

我有一个名为Core.proj的iOS项目,包括SalesForce SDK,它是用Objective-C编写的。该项目使用SF SDK并将二进制文件链接到SF库。它做了很多事情来帮助我管理SF的实现。它包含在我的所有其他Obj-C项目中,并且在其中工作得非常好

这是我第一次在Swift(2.1)中使用这个项目。我正在使用iOS9和Xcode 7.1.1。我在Swift项目中添加了Core.xcodeproj。然后我创建了一个ObjC文件。然后,Xcode询问我是否要创建桥接头。我愿意。我已经创建了一个名为Swift bridge header.h的桥接头。这使我能够通过桥接头访问Core.xcodeproj中的文件。例如,我可以从桥接头访问自己版本的Salesforce Authentication Manager

在我的AppDelegate中,我现在想启动OAuth(我在这里保持这个最小值):

完全公开:您在这里看到的每个块都将SFOAuthInfo对象作为参数。为了让斯威夫特阅读这个区块,我必须将SFOAuthInfo.h添加到复制文件中

现在,所有这些都可以编译,但当我点击登录并执行上述代码时,会出现以下错误:

    2015-12-04 11:53:54.879 MyApp[19108:3494140] -[UIDevice    macaddress]: unrecognized selector sent to instance 0x7fcfb4903230
2015-12-04 11:53:54.890 MyApp[19108:3494140] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDevice macaddress]: unrecognized selector sent to instance 0x7fcfb4903230'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010d6adf65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010f624deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010d6b658d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010d603f7a ___forwarding___ + 970
    4   CoreFoundation                      0x000000010d603b28 _CF_forwarding_prep_0 + 120
    5   MyApp                  0x000000010c869317 -[SFOAuthCredentials keyMacForService:] + 84
    6   MyApp                  0x000000010c8696b8 -[SFOAuthCredentials updateTokenEncryption] + 210
    7   MyApp                  0x000000010c8673ee -[SFOAuthCredentials initWithIdentifier:clientId:encrypted:] + 211
    8   MyApp                  0x000000010c84102c -[SFUserAccount initWithIdentifier:] + 197
    9   MyApp                  0x000000010c85f32d -[SFUserAccountManager createUserAccount] + 91
    10  MyApp                  0x000000010c831b41 -[SFAuthenticationManager loginWithCompletion:failure:account:] + 284
    11  MyApp                  0x000000010c831a0b -[SFAuthenticationManager loginWithCompletion:failure:] + 53
    12  MyApp                  0x000000010c60440c -[MyAuthenticationManager loginWithCompletion:failure:] + 124
    13  MyApp                  0x000000010c5dc58f _TFC18MyApp11AppDelegate5loginfS0_FT_T_ + 911
    14  MyApp                  0x000000010c5dfdc4 _TFC18MyApp25LandingPageViewController17loginButtonTappedfS0_FPSs9AnyObject_T_ + 68
    15  MyApp                  0x000000010c5dfe16 _TToFC18MyApp25LandingPageViewController17loginButtonTappedfS0_FPSs9AnyObject_T_ + 54
    16  UIKit                               0x000000010e1af1fa -[UIApplication sendAction:to:from:forEvent:] + 92
    17  UIKit                               0x000000010e313504 -[UIControl sendAction:to:forEvent:] + 67
    18  UIKit                               0x000000010e3137d0 -[UIControl _sendActionsForEvents:withEvent:] + 311
    19  UIKit                               0x000000010e312906 -[UIControl touchesEnded:withEvent:] + 601
    20  UIKit                               0x000000010e219aa3 -[UIWindow _sendTouchesForEvent:] + 835
    21  UIKit                               0x000000010e21a691 -[UIWindow sendEvent:] + 865
    22  UIKit                               0x000000010e1cc752 -[UIApplication sendEvent:] + 263
    23  UIKit                               0x000000010e1a7fcc _UIApplicationHandleEventQueue + 6693
    24  CoreFoundation                      0x000000010d5da0a1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    25  CoreFoundation                      0x000000010d5cffcc __CFRunLoopDoSources0 + 556
    26  CoreFoundation                      0x000000010d5cf483 __CFRunLoopRun + 867
    27  CoreFoundation                      0x000000010d5cee98 CFRunLoopRunSpecific + 488
    28  GraphicsServices                    0x0000000113e46ad2 GSEventRunModal + 161
    29  UIKit                               0x000000010e1ad676 UIApplicationMain + 171
    30  MyApp                  0x000000010c5ddd8d main + 109
    31  libdyld.dylib                       0x00000001107a592d start + 1
    32  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
SF SDK有一个名为UIDevice+SFHardware.h的类别。在这个类别中有一个名为“macaddress”的方法。因此,很明显,它没有正确解读这一类别。但是为什么呢?从堆栈跟踪中可以看到,它正在正确读取SF SDK中的其他文件

我尝试了很多方法来让它发挥作用。例如,这个:但是使用UIDevice+SFHardware.h。我试过这个:。我再次完全重建了项目以检查我的工作

我不需要将这个文件添加到我的网桥中,因为这个UIDevice+SFHardware.h只能从位于ObjC项目中的SF SDK访问


不过我一定是做错了什么。任何帮助都将不胜感激

我刚刚讨论了这个问题

在项目>生成设置>其他链接器标志中添加: -ObjC -全负荷


我的SalesforceSDK在我的Pod项目中。如果您也这样做,请在SalesforceMobileSDK iOS项目中设置这些标志。如果不是,那么无论Salesforce SDK在哪里编译。

事实证明,这是多种因素的组合。首先,我在Swift项目和ObjC项目中都缺少-ObjC链接器标志。感谢DarthVadar123451指出这一点。但我也意识到我缺少了两个库:libz.dylib和libxml2.dylib。一旦添加,一切都起作用了。我希望这能帮助任何遇到同样问题的人

    2015-12-04 11:53:54.879 MyApp[19108:3494140] -[UIDevice    macaddress]: unrecognized selector sent to instance 0x7fcfb4903230
2015-12-04 11:53:54.890 MyApp[19108:3494140] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDevice macaddress]: unrecognized selector sent to instance 0x7fcfb4903230'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010d6adf65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010f624deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010d6b658d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010d603f7a ___forwarding___ + 970
    4   CoreFoundation                      0x000000010d603b28 _CF_forwarding_prep_0 + 120
    5   MyApp                  0x000000010c869317 -[SFOAuthCredentials keyMacForService:] + 84
    6   MyApp                  0x000000010c8696b8 -[SFOAuthCredentials updateTokenEncryption] + 210
    7   MyApp                  0x000000010c8673ee -[SFOAuthCredentials initWithIdentifier:clientId:encrypted:] + 211
    8   MyApp                  0x000000010c84102c -[SFUserAccount initWithIdentifier:] + 197
    9   MyApp                  0x000000010c85f32d -[SFUserAccountManager createUserAccount] + 91
    10  MyApp                  0x000000010c831b41 -[SFAuthenticationManager loginWithCompletion:failure:account:] + 284
    11  MyApp                  0x000000010c831a0b -[SFAuthenticationManager loginWithCompletion:failure:] + 53
    12  MyApp                  0x000000010c60440c -[MyAuthenticationManager loginWithCompletion:failure:] + 124
    13  MyApp                  0x000000010c5dc58f _TFC18MyApp11AppDelegate5loginfS0_FT_T_ + 911
    14  MyApp                  0x000000010c5dfdc4 _TFC18MyApp25LandingPageViewController17loginButtonTappedfS0_FPSs9AnyObject_T_ + 68
    15  MyApp                  0x000000010c5dfe16 _TToFC18MyApp25LandingPageViewController17loginButtonTappedfS0_FPSs9AnyObject_T_ + 54
    16  UIKit                               0x000000010e1af1fa -[UIApplication sendAction:to:from:forEvent:] + 92
    17  UIKit                               0x000000010e313504 -[UIControl sendAction:to:forEvent:] + 67
    18  UIKit                               0x000000010e3137d0 -[UIControl _sendActionsForEvents:withEvent:] + 311
    19  UIKit                               0x000000010e312906 -[UIControl touchesEnded:withEvent:] + 601
    20  UIKit                               0x000000010e219aa3 -[UIWindow _sendTouchesForEvent:] + 835
    21  UIKit                               0x000000010e21a691 -[UIWindow sendEvent:] + 865
    22  UIKit                               0x000000010e1cc752 -[UIApplication sendEvent:] + 263
    23  UIKit                               0x000000010e1a7fcc _UIApplicationHandleEventQueue + 6693
    24  CoreFoundation                      0x000000010d5da0a1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    25  CoreFoundation                      0x000000010d5cffcc __CFRunLoopDoSources0 + 556
    26  CoreFoundation                      0x000000010d5cf483 __CFRunLoopRun + 867
    27  CoreFoundation                      0x000000010d5cee98 CFRunLoopRunSpecific + 488
    28  GraphicsServices                    0x0000000113e46ad2 GSEventRunModal + 161
    29  UIKit                               0x000000010e1ad676 UIApplicationMain + 171
    30  MyApp                  0x000000010c5ddd8d main + 109
    31  libdyld.dylib                       0x00000001107a592d start + 1
    32  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException