18

I have an Xcode project, Xcode 8.1 (8B62) with two targets, one for the paid version of the application and the other for the free version. They both manage remotes push notifications. Since I made the changes for iOS 10 with the new framework UNUserNotificationCenter.framwork, everything is fine for the first target and I have a link error for the second. It worked well under iOS 9 with the old methods. What I did for both targets:

  • Capabilities: Enabled Push Notifications (Entitlements are properly updated)
  • In AppDelegate.h: #import
  • In AppDelegate.m: Updated the code with the new methods

It's the same code for both targets.

Unfortunately, for the second target, I have the following error:

Undefined symbols for architecture arm64:   "_OBJC_CLASS _ $ _ UNUserNotificationCenter", referenced from:       Objc-class-ref in AppDelegate.o Ld: symbol (s) not found for architecture Clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have done several times clean and clean build target folder, re-start Xcode, re-start the computer but nothing is done.

Nothing found in the different forums ...

Help would be welcome. Thank you in advance.

shallowThought
  • 19,212
  • 9
  • 65
  • 112
Patrick Bodet
  • 641
  • 2
  • 8
  • 17

3 Answers3

43

You are not linking to the UserNotifications.framework.

  • Select your target
  • Show its "Build Phases"
  • Assure UserNotifications.framework exists in "Link Binary With Libraries"

If it does not:

  • Click "+" button and add it
shallowThought
  • 19,212
  • 9
  • 65
  • 112
  • Thanks but I don't think it is necessary. I tried but without success. In the first target, the framework is not added. I think Xcode takes care about this framework automatically from the moment that the remotes push notifications are activated in the capabilities. – Patrick Bodet Nov 19 '16 at 11:20
  • Thank, apologies, when I tried, I was wrong about framework, I added NotificationCenter.framework. But what is this one? And why the first target is OK, as I did not add the framework too? – Patrick Bodet Nov 19 '16 at 11:48
  • You wrote that you are using "...the new UNUserNotificationCenter...". (Not "the old NSNotificationCenter"). To be true, I never understood when it is necessary to add a library here. But I know it helps if the linker can not find it. I suspect issues with the "it magically works" build settings generated by Xcode. But this is only a guess. Did it work out for you now? – shallowThought Nov 19 '16 at 11:56
  • Yes it works, thanks. For the first target it was magic! I also add the framework anyway... – Patrick Bodet Nov 19 '16 at 12:07
  • 8
    Remember to add `import UserNotifications` – Piotr Badura Aug 14 '17 at 13:32
  • @PatrickBodet did you have "Enable Modules" YES in the one that worked like "magic" and didn't have to add the framework? If so, that may be the reason .. – auspicious99 Sep 15 '17 at 14:07
  • @shallowThought I think I may know what causes "it magically works" in some cases. – auspicious99 Sep 15 '17 at 14:07
2

I had almost exactly the same problem, with two targets, one for the free version, one for the paid version.

I strongly suspect that the difference was that with one target, "Enable modules" was YES (this was the target for the free version, where I was doing an @import for Admob), whereas with the other target, "Enable modules" was NO. Like magic, I didn't have to add UserNotifications.framework in "Link Binary with Libraries" in Build Phases for the target where "Enable modules" was YES. However, for the target where "Enable modules" was NO, I got

Undefined symbols for architecture arm64:   "_OBJC_CLASS _ $ _ UNUserNotificationCenter

and it went away by manually adding UserNotifications.framework to "Link Binary with Libraries".

So maybe the rule is, this needs to be done if and only if modules are not enabled.

auspicious99
  • 3,902
  • 1
  • 44
  • 58
1

Make sure UserNotifications.framework exists in your Target > General > Linked Frameworks and Libraries

Munahil
  • 2,381
  • 1
  • 14
  • 24
  • Thanks a lot, did the trick, but UserNotifications.framework does not exist in the first target! And it works! – Patrick Bodet Nov 19 '16 at 11:35
  • how about you duplicate your first target again and make changes (if there are not many). This might fix this. – Munahil Nov 19 '16 at 11:38