google / gtm-oauth2

Google Toolbox for Mac - OAuth 2 Controllers
Apache License 2.0
125 stars 70 forks source link

Missing GTMOAuth2ViewTouch.nib when built at framework #63

Closed erickoledadevrel closed 8 years ago

erickoledadevrel commented 8 years ago

When building the project as a framework, for instance by include use_frameworks! in the Podfile, using the library will result in a black screen and an error like:

MyApp[123:456]: missing GTMOAuth2ViewTouch.nib

The root of the problem seems to be that the code is looking for the nib/xib in the main bundle, which isn't correctly when the library is included as a framework. As per the Cocoapods documentation on frameworks, the library should use NSBundle bundleForClass instead of NSBundle mainBundle when looking for the resources, to ensure it works correctly whether built as a static library or a framework.

perotinus commented 8 years ago

@erickoledadevrel Appreciate the PR! Do you think you'll be able to sign the CLA?

erickoledadevrel commented 8 years ago

I work at Google, so I didn't think it was required. On Apr 20, 2016 9:53 PM, "Jonathan MacMillan" notifications@github.com wrote:

@erickoledadevrel https://github.com/erickoledadevrel Appreciate the PR! Do you think you'll be able to sign the CLA?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/google/gtm-oauth2/issues/63#issuecomment-212692512

erickoledadevrel commented 8 years ago

I fixed my email address on the commit, so CLABot is happy :-)

weibel commented 7 years ago

We're still seeing this on 1.1.4 after migrating to use_frameworks! on CocoaPods.

weibel commented 7 years ago

The problem was that we had subclassed GTMOAuth2ViewControllerTouch. In that case [NSBundle bundleForClass:[self class]] will give you the main bundle.

Inserting the following in the child class solved the problem, but there might be a more elegant solution.

+ (NSBundle *)authNibBundle {
   // subclasses may override this to specify a custom nib bundle
   return [NSBundle bundleForClass:[GTMOAuth2ViewControllerTouch class]];
}