4

I'm following this guide on adding OneSignal to React Native, and there is one section where is says:

Open NotificationService.m or NotificationService.swift and replace the whole file contents with the code below:

<provides code to add>

If you are using Swift, make sure to create a separate Objective-C Bridging Header for your OneSignalNotificationExtensionService and add the following import:

#import "RCTOneSignalExtensionService.h" Then you need to tell your Xcode project settings what your bridging header is named, like this.

I added the code they provided to NotificationService.swift because that's the only one of the two files that exists in my project. So I assume I'm "using swift" as they put it. The problem is that when they say to create a separate Objective-C Bridging Header, I don't know how to do that. All I've been able to find online is that when you import Objective-C code into your swift project, Xcode should automatically prompt you to create a bridging header. Xcode hasn't done that for me.

Does anyone know how I can create an Objective-C bridging header?

Murmeltier
  • 595
  • 5
  • 10
gkeenley
  • 6,088
  • 8
  • 54
  • 129

1 Answers1

1

You have to create a new objective c class:

You select New File

then

select cocoa touch class

then you name it and specify as objective-c class at language

select objective-c as language

then you select your directory and hit create. At this point xcode is going to ask you whether or not you want to create bridging header. Yep do it.

enter image description here

And at the end it should look more or less like this at your project.

Job done

hope that helps you.

Murmeltier
  • 595
  • 5
  • 10
  • It just says to create a bridging header. Are you sure that I have to create a whole Objective-C class instead of just creating the header file? – gkeenley Apr 15 '20 at 15:51
  • Well you can do it by just adding a bridge header manually but you will have set building settings to that bridge header. Or you can just add a class and xcode will do that for you. Up to you https://stackoverflow.com/questions/31716413/xcode-not-automatically-creating-bridging-header – Murmeltier Apr 15 '20 at 16:03
  • briding header sometimes isn't created with these actions so answer is useless – Vyachaslav Gerchicov Aug 04 '20 at 12:34
  • 1
    This answer relies on tricking Xcode into noticing that you need the header. Sometimes work, sometimes doesn't. In Xcode 12, for instance, this never works. – Bill Patterson Aug 25 '20 at 17:22