Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNUserNotificationCenter link error

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.

like image 722
Patrick Bodet Avatar asked Nov 19 '16 10:11

Patrick Bodet


3 Answers

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
like image 88
shallowThought Avatar answered Oct 23 '22 23:10

shallowThought


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.

like image 22
auspicious99 Avatar answered Oct 23 '22 21:10

auspicious99


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

like image 1
Munahil Avatar answered Oct 23 '22 22:10

Munahil