V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
jpush

React Native 一些事

  •  
  •   jpush ·
    jpush · Apr 21, 2017 · 1899 views
    This topic created in 3294 days ago, the information mentioned may be changed or developed.

    ReactJS 是否准备好

    有时候我们常常需要监听 ReactJS 的的加载情况。 比如说,当获取一条推送,应用还没有起来,通过点击推送启动应用后,而推送中包含一些我们感兴趣的字段需要处理,我们如果直接把这条通知发送给 ReactJS ,会有一个问题,就是应用是刚启动的, ReactJS 还没有成功加载,推送直接发送会出现丢失。所以我们可以吧这条推送缓存起来,等待 ReactJS 成功加载后再发送。此时可以监听如下事件,获悉 ReactJS 的加载状况。

    RCTJavaScriptWillStartLoadingNotification
    RCTJavaScriptDidLoadNotification
    RCTJavaScriptDidFailToLoadNotification
    

    第三方应用唤起自己应用

    应用被 URL 唤起, 自己的应用 A ,被其他应用 B 唤醒, 如果你需要在 A 应用处理应用 B 传递的过来的参数,需要处理 openurl , 参数通过 url 传递过来。获取 url 的方法如下

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    {
      return [RCTLinkingManager application:application openURL:url
                          sourceApplication:sourceApplication annotation:annotation];
    }
    
    componentDidMount() {
      Linking.addEventListener('url', this._handleOpenURL);
    },
    componentWillUnmount() {
      Linking.removeEventListener('url', this._handleOpenURL);
    },
    _handleOpenURL(event) {
      console.log(event.url);
    }
    

    获取 ReactJS 运行环境

    RCTJavaScriptContextCreatedNotification 是一个有意思的通知, React native 是通过 JSContext 来实现 JS 调用 OC 的方法。 JSContext 在成功创建后 会发送 RCTJavaScriptContextCreatedNotification 这个通知,并且携带 JSContext 参数。 OC 可以直接获得 ReactJS 的运行环境。


    作者: HuminiOS - 极光( JPush 为极光团队账号,欢迎关注)

    原文:React Native 一些事

    知乎专栏:极光日报

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1160 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:05 · PVG 02:05 · LAX 11:05 · JFK 14:05
    ♥ Do have faith in what you're doing.