23

I'm trying to integrate OneSignal SDK in Xcode 7.2.1 with CocoaPods 1.0.0.beta.2 and use_frameworks! directive. When I try to import the framework in AppDelegate.swift I get

No such module 'OneSignal'.

I also have other frameworks included from Cocoapods which work with no problem (ex: Fabric)

I managed to install OneSignal SDK with cocoapods in another project, but without the use_frameworks! directive. I used the bridging header.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Mihai
  • 711
  • 1
  • 9
  • 14
  • Just a stab in the dark, but I've always had to build the project after installing new pods before I can import them. This was the case again when I installed the OneSignal SDK using #use_frameworks. Hope it helps – Ollie Feb 05 '16 at 09:42
  • I've noticed that too. But I built and rebuilt the project several times, cleaned it and the build folder, restarted Xcode. No luck so far. @Ollie , does OneSignal work for you with #use_frameworks ? – Mihai Feb 06 '16 at 17:09
  • I've got the #use_frameworks in my podfile as I have other pods that work with that, although to use OneSignal I also had to use a bridging header. I realise my first comment was maybe a little misleading! (Sorry!!) They specify in the getting started guide that you need a bridging header in swift. https://documentation.onesignal.com/docs/installing-the-onesignal-ios-sdk – Ollie Feb 08 '16 at 10:26
  • You should post this as an answer. I managed to do it by adding the bridging header. I thought the bridging header is not needed if you have use_frameworks. Actually I didn't think it was possible to have both use_frameworks and bridging header. Silly me – Mihai Feb 09 '16 at 12:04
  • Ok will do, glad it's solved! – Ollie Feb 09 '16 at 12:54

8 Answers8

12

Pods written in Swift can be imported with the use_frameworks!, and CocoaPods will complain if you don't do this and try to import the pods in Swift code.

Although any pods not written in Swift, will require the use of a bridging header.

Referencing to the OneSignal pod, the getting-started guide instructs applications using Swift to include a bridging header in order to use the pod. OneSignal: Getting Started Guide

Ollie
  • 1,926
  • 1
  • 20
  • 35
10

You need to type these commands. It has fixed it for me:

$ pod deintegrate
$ pod install

My Podfile:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Your_Project_Name' do
  # Comment the next line if you don't want to use dynamic frameworks

  # Pods for Das Gedenken
pod 'OneSignal'


end

target 'OneSignalNotificationServiceExtension' do
  #only copy below line
  pod 'OneSignal'
end
SwiftiSwift
  • 7,528
  • 9
  • 56
  • 96
6

if you have already pod file before starting development OneSignal, you need to add new target for OneSignalNotificationServiceExtension.

    target 'OneSignalNotificationServiceExtension' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for OneSignalNotificationServiceExtension
  pod 'OneSignal', '>= 2.5.2', '< 3.0'

  end

After the adding above code to the podfile. You must "pod install" one again.

Emre Gürses
  • 1,992
  • 1
  • 23
  • 28
4

With OneSignal 5.0.0 (on Flutter) I had to use:

import OneSignalFramework

instead of

import OneSignal
Westy92
  • 19,087
  • 4
  • 72
  • 54
1

Another thing to mention is that Getting error "No such module" using Xcode, but the framework is there

If the framework header is already included in the bridging header file then you don't have to import it in the Swift source file.

Community
  • 1
  • 1
onmyway133
  • 45,645
  • 31
  • 257
  • 263
1

EDIT

Is OneSignal cocoapod written in Swift or not? Do I need use_frameworks! or bridging header? What works in Xcode 8.2.1, Swift 3 and OneSignal (1.11.3) ?

  1. OneSignal: Getting Started Guide did not actually work in Swift 3
  2. adding import OneSignal to AppDelegate.swift actually didn't work for me
    (no autocomplete & compilation error)
  3. use_frameworks! is of no help in this specific situation

Xcode 8.2.1, Swift 3, OneSignal 1.11.3

  • Use this bridging header (†):

    #import "OneSignal/OneSignal.h"
    
  • In the App Delegate:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions
                     launchOptions: [UIApplicationLaunchOptionsKey: Any]?)
                     -> Bool {
        _ = OneSignal.init(launchOptions: launchOptions,
                           appId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
        ...
    }
    

  • (†) An easy way to add a properly setup bridging header is to simply add a new Objective-C source file to the project and follow the dialogs. Configure bridging headers
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • there is already a valid answer specifying the use of a bridging header. why would you post another one? – Mihai Jan 04 '17 at 20:05
  • 1
    Good point. Answer is about the specifics of what the bridging header actually contains, and how the invocation looks in Swift 3, in direct conflict with OneSignal tutorial. – SwiftArchitect Jan 04 '17 at 22:40
  • 1
    Thanks for this. Helped me. – palme Jan 07 '17 at 13:08
0

BUILDING(CMD+B) the project immediately after installing the pods before start using the pod helps. And also we have to clear all the error before start using the pods.

NiranjanB
  • 59
  • 1
  • 9
0

try this out: Go to Product > Schemes > New Scheme... Select the name of your Cocoapod then click OK. After you do this, build the project.