开发者

Duplicate symbols, GTMOAuth2 and Facebook SDK for IOS both using SBJSON

开发者 https://www.devze.com 2023-03-18 00:49 出处:网络
I have an app in which I have implemented facebook login. I copied the sources from the facebook sdk directly into my project. Now I need to add google login. This time I have added GTMOAuth2 as a sta

I have an app in which I have implemented facebook login. I copied the sources from the facebook sdk directly into my project. Now I need to add google login. This time I have added GTMOAuth2 as a static library. (I also have the source for this too but I 开发者_StackOverflow中文版added as a static library for no specific reason). The problem is they are both using SBJson and I get duplicate symbols. It appears that the SBJson in the facebook sdk is newer than the one in the GTMOAuth2 library. I'm a noob I never had duplicate symbols before, what should I do? Are there solutions to this specific problem or to resolving duplicate symbols in general? Do I just delete stuff that appears twice until it works, are there some linker settings? Thanks.

Update - What I tried:

Added both projects as a static library.

  • I tried deleting the SBJSON.h/m files from GTMOAuth2, result: json parse error after google login:

  • I tried deleting the SBJSON.h/m files from the Facebook iOS SDK; result: json parse error after facebook login.

Can I make these two versions of SBJSON magically coexist in my app without duplicate symbols? Do I have to modify one library to work with the ONE SBJSON I decite to use?


I'm using SBJSON from the facebook sdk. I just removed SBJSON from the GTMOAuth2 library to avoid duplicate symbol as suggested by Ishu. The next problem is that GTMOAuth2 tries to use SBJSONParser first and that class doesn't have objectWithString:error: method, only SBJSON has the method. I modified the code to use SBJSON class, and don't even try to use SBJSONParser because it doesn't work. In the original version SBJsonParser was checked first and then SBJSON.



- (NSDictionary *)dictionaryWithJSONData:(NSData *)data {
    ...
    // try SBJsonParser or SBJSON
    Class jsonParseClass = NSClassFromString(@"SBJSON");
    /*
    if (!jsonParseClass) {
      jsonParseClass = NSClassFromString(@"SBJsonParser");
    }
    */
    if (jsonParseClass) {
      GTMOAuth2ParserClass *parser = [[[jsonParseClass alloc] init] autorelease];
      NSString *jsonStr = [[[NSString alloc] initWithData:data
                                                 encoding:NSUTF8StringEncoding] autorelease];
      if (jsonStr) {
        obj = [parser objectWithString:jsonStr error:&error];
#if DEBUG
        if (error) {
          NSLog(@"%@ error %@ parsing %@", NSStringFromClass(jsonParseClass),
                error, jsonStr);
        }
#endif
        return obj;
      }
    }
  ...
}

UPDATE Here I asked the same question in the GTM-OAuth2 discussion group. This happened after I answered the question, but I forgot to update my answer here. In summary this is what I did:

  • Use both Facebook SDK and GTMOAuth2 as static libraries (probably this is not necessary)
  • Get latest version of SBJSON from here
  • Replace the SBJSON in Facebook SDK with this one
  • Delete the SBJSON sources from GTM-OAuth2 (or remove them from the build phase)

This leaves you with the most up to date SBJSON library included in the Facebook SDK. Both Facebook SDK and GTM-OAuth2 will use that one. It should work.


yes delete the SBJSON of GTMOAuth2 library (since it is older version).

0

精彩评论

暂无评论...
验证码 换一张
取 消