自定义编写的iOS本机模块未导出

时间:2018-07-29 22:00:18

标签: ios react-native

正如我的标题所述,我在react native中创建了一个裸露的iOS本机模块,它没有出现在最终的<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/readmore-js@2.1.0/readmore.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="example col-md-12"> <p>They say everything looks better with odd numbers of things. But sometimes I put even numbers—just to upset the critics. Don't be afraid to make these big decisions. Once you start, they sort of just make themselves. Now let's put some happy little clouds in here. We can always carry this a step further. There's really no end to this. Think about a cloud. Just float around and be there. We want to use a lot pressure while using no pressure at all.</p> <p>Look around, look at what we have. Beauty is everywhere, you only have to look to see it. That's the way I look when I get home late; black and blue. All you have to do is let your imagination go wild. We have a fantastic little sky!</p> <p>All kinds of happy little splashes. We don't want to set these clouds on fire. I was blessed with a very steady hand; and it comes in very handy when you're doing these little delicate things. It looks so good, I might as well not stop. We need dark in order to show light. I really recommend you use odorless thinner or your spouse is gonna run you right out into the yard and you'll be working by yourself.</p> <img src="https://dummyimage.com/200x200/2d5cc2/fff" /> <p>Van Dyke Brown is a very nice brown, it's almost like a chocolate brown. We're trying to teach you a technique here and how to use it. This present moment is perfect simply due to the fact you're experiencing it.</p> <p>If what you're doing doesn't make you happy - you're doing the wrong thing. We spend so much of our life looking - but never seeing. In this world, everything can be happy. Everyone is going to see things differently - and that's the way it should be. And just raise cain.</p> <p>There's nothing wrong with having a tree as a friend. Maybe there was an old trapper that lived out here and maybe one day he went to check his beaver traps, and maybe he fell into the river and drowned. Tree trunks grow however makes them happy.</p> <p>Let your imagination be your guide. You could sit here for weeks with your one hair brush trying to do that - or you could do it with one stroke with an almighty brush. We wash our brush with odorless thinner. Every highlight needs it's own personal shadow. Don't kill all your dark areas - you need them to show the light. Working it up and down, back and forth.</p> <p>Don't forget to tell these special people in your life just how special they are to you. The only thing worse than yellow snow is green snow. That's why I paint - because I can create the kind of world I want - and I can make this world as happy as I want it. Let's build an almighty mountain. You have to make almighty decisions when you're the creator.</p> <p>We have a fantastic little sky! Everybody's different. Trees are different. Let them all be individuals. Just go out and talk to a tree. Make friends with it. Go out on a limb - that's where the fruit is. There are no mistakes. You can fix anything that happens.</p> <p>You have to make those little noises or it won't work. We have no limits to our world. We're only limited by our imagination. I want everbody to be happy. That's what it's all about.</p> <p>Nice little clouds playing around in the sky. It's a super day, so why not make a beautiful sky? We spend so much of our life looking - but never seeing. The secret to doing anything is believing that you can do it. Anything that you believe you can do strong enough, you can do. Anything. As long as you believe. Everything's not great in life, but we can still find beauty in it.</p> <p>If you've been in Alaska less than a year you're a Cheechako. You don't have to be crazy to do this but it does help. I'm going to mix up a little color. We’ll use Van Dyke Brown, Permanent Red, and a little bit of Prussian Blue. And I will hypnotize that just a little bit. Nothing's gonna make your husband or wife madder than coming home and having a snow-covered dinner.</p> <p>There it is. Don't fiddle with it all day. No worries. No cares. Just float and wait for the wind to blow you around.</p> <p>All you need to paint is a few tools, a little instruction, and a vision in your mind. Let's put a touch more of the magic here. Now let's put some happy little clouds in here. We'll lay all these little funky little things in there. But we're not there yet, so we don't need to worry about it. All you have to learn here is how to have fun.</p> </div> javascript对象中。这正是我在做什么。我对此深感困惑。

  1. 使用NativeModules创建新项目
  2. 在xcode中打开react-native init testproj的ios文件夹,并创建一个名为testproj的{​​{1}}
  3. Cocoa Touch Class中,我有以下内容:

    MyModule
  4. MyModule.h中,我有以下内容:

    #import <React/RCTBridgeModule.h>
    
    @interface MyModule : NSObject <RCTBridgeModule>
    @end
    
  5. 我运行MyModule.m,应用成功构建。当像这样打印#import "MyModule.h" @implementation MyModule RCT_EXPORT_MODULE() @end 时:

    react-native run-ios

    我在控制台日志中没有看到NativeModules,但是我看到所有基本的反应本机模块。

有人对为什么会发生有任何想法吗?我在xcode构建阶段中缺少什么?有关更多信息,请参阅以下相关版本:

  • import React, {Component} from 'react'; import {NativeModules} from 'react-native' export default class App extends Component { componentWillMount() { console.log('my modules! ', NativeModules) } render() { ... } } MyModule
  • xcode 9.4.1
  • react 16.4.0
  • react-native模拟器上运行

1 个答案:

答案 0 :(得分:1)

React Native如果没有任何方法,则不会公开您的本机模块。 您需要使用RCT_EXPORT_METHOD(或RCT_REMAP_METHOD)宏导出至少一种方法,然后才能访问它。