Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding libGrowingIORNPlugin.a can not use location. [iOS] #4

Closed
FaiChou opened this issue Jul 3, 2018 · 8 comments
Closed

Adding libGrowingIORNPlugin.a can not use location. [iOS] #4

FaiChou opened this issue Jul 3, 2018 · 8 comments

Comments

@FaiChou
Copy link

FaiChou commented Jul 3, 2018

After I adding react-native-growingio to my project, location just broke up.

exception

After tried remove .a, location works well !!

Location is a big part of my project's feature, after launch app to home page, it will get current position. It is very well before adding libGrowingIORNPlugin.a . But .

PS. I added LocationAlwaysUse, LocationAlwaysUseAndWhileUse, LocationUsage, LocationWhenInUse these four descriptions to info.plist.

My environment:

Environment:
  OS: macOS High Sierra 10.13.5
  Node: 9.5.0
  Yarn: 1.5.0
  npm: 5.7.1
  Watchman: 4.9.0
  Xcode: Xcode 9.4.1 Build version 9F2000
  Android Studio: 3.1 AI-173.4720617

Packages: (wanted => installed)
  react: 16.3.1 => 16.3.1
  react-native: 0.55.4 => 0.55.4
@NanNanCHN
Copy link
Contributor

@FaiChou 你好,这个问题的原因是growingio 的hook机制有向delegate注册kvo的操作,触发了facebook的断言,而facebook的断言没有包含这种情况的判断 从而造成了您的不便;

解决方式:
1.因为让facebook改代码的周期会很长,您可以先注释掉RCTEventEmitter.m中

RCTAssert(RCTClassOverridesInstanceMethod(self, @selector(supportedEvents)),
              @"You must override the `supportedEvents` method of %@", self);

这句断言,查看位置功能是否正常工作

@FaiChou
Copy link
Author

FaiChou commented Jul 3, 2018

@NanNanCHN

这是个临时解决的方法. 试了下可以的.

每次执行yarn 都需要手动更改吧?
而且多人协作的项目也得让其他参与的同事都改吧?

react-native-growingio 啥时候能优化掉这个bug?

@NanNanCHN
Copy link
Contributor

@FaiChou
这确实是临时解决方式,而且存在一定工程风险.
本质上来讲,这是facebook的bug,不属于growingio的问题,暂时不清楚facebook何时以及是否会改.
你提到的多人协作项目的问题,这里可以给你个参考,用method swizzing 去让RCTEventEmitter 的initialize方法不执行原实现即可;
或者
可以尝试解决方式2 看是否奏效:
在main.m中添加

[Growing setAspectMode:GrowingAspectModeDynamicSwizzling];

使用第二种hook模式

@FaiChou
Copy link
Author

FaiChou commented Jul 4, 2018

好的谢谢.

使用第二种不行.

尝试第一种method swizzle也未果, 还是用手动注释方法吧.

我的尝试方法:

#import "RCTEventEmitter+RNSwizzle.h"
#import <objc/runtime.h>

@implementation RCTEventEmitter (RNSwizzle)
+ (void)load {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    Class class = [self class];
    
    SEL originalSelector = @selector(initialize);
    SEL swizzledSelector = @selector(swizzledInitialize);
    
    Method originalMethod = class_getInstanceMethod(class, originalSelector);
    Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
    
    method_exchangeImplementations(originalMethod, swizzledMethod);
  });
}
+ (void)swizzledInitialize {
  if (self == [RCTEventEmitter self]) {
    // just doing nothing!
  }
}

@end

@NanNanCHN
Copy link
Contributor

@FaiChou 方便的话可否给我一个可以复现的demo

@FaiChou
Copy link
Author

FaiChou commented Jul 4, 2018

rn demo splash页结束后跳到home页, home页在willmount进行请求地理位置, 立马报错. (添加了growingio.a 后)

  public componentDidMount() {
    this.fetchLocation();
  }

  private fetchLocation = () => {
    getLongitudeAndLatitude().then(({longitude, latitude}) => {
      getLocation(longitude, latitude).then((po) => {
        this.props.dispatch({
          type: 'address/changeAddress',
          payload: po,
        });
        CurrentCity.cityname = po.city;
        CurrentCity.citycode = po.citycode;
      });
    }).catch(ex => {
      Log('定位失败', ex);
    });
  }

@NanNanCHN
Copy link
Contributor

rn-patch.zip

@FaiChou 你可以在工程中引入这个patch fix这个问题,日后如果facebook 修掉了,可以把patch删除

@FaiChou
Copy link
Author

FaiChou commented Jul 6, 2018

OK. 可以使用 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants