Ios – ‘sharedApplication’ is unavailable: not available on iOS (App Extension)

cocoapodsiosobjective cswiftxcode

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

Best Answer

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.