0
votes

I'm building an app and developed a Today Extension for it a month or two ago. Randomly, while running it maybe the 10th time in in iOS 11 Beta, I got an error for the first time and now the entire app will not build.

/Users/Documents/AppName/Pods/CarbonKit/CarbonKit/CarbonTabSwipeNavigation.m:622:27: 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.

The error appears in a Pod, but it's in a file that in written in Obj-C, not Swift, so it is hard to understand.

These are the lines the error appears on:

  // Some projects use GTM_BACKGROUND_TASK_FETCHING to avoid compile-time references
  // to UIApplication.
#if GTM_BACKGROUND_TASK_FETCHING
  return (id<GTMUIApplicationProtocol>) [UIApplication sharedApplication]; <- error
#else
  return nil;
#endif

Could anyone give advice on how to solve this error? Any help would be immensely appreciated. Thanks a ton in advance!

Cheers, Theo

2
@rmaddy why did you get rid of my swift tag? i put it there because my app is written in swift, so it is pertinent to this issue. - Theo Strauss
Have you looked at what google has to say on this subject? I stopped skimming after the second page of results. - danh
@rmaddy i did mention that its written in swift. "...written in Obj-C, not Swift, so it is hard to understand." - Theo Strauss
@danh yeah i tried. all related to other pods, not carbon kit. i found something abt alamofire but the answer was completely different than my case. thanks though - Theo Strauss
If you look at the description for the swift tag it says "Use the tag only for questions about language features, or requiring code in Swift." As such there is no reason to remove the tag. - shim

2 Answers

3
votes

This worked for me. Go to your target build settings and find Require Only AppExtension-Safe API and set the value to No. This will silence this error.

2
votes

As the error clearly states, the following API is not available for use in Today Extensions:

[UIApplication sharedApplication]

Please read the Apple provided documentation on App Extensions:

Some APIs Are Unavailable to App Extensions

Because of its focused role in the system, an app extension is ineligible to participate in certain activities. An app extension cannot:

  • Access a sharedApplication object, and so cannot use any of the methods on that object

- Apple, App Extension Programming Guide

Make sure that CarbonKit (or, really, anything that uses these APIs) is not included in your Today App Extension target. Xcode should have automatically warned you about this as soon as it was included in your extension target (although it is possible to silence these warnings temporarily).