google / promises

Promises is a modern framework that provides a synchronization construct for Swift and Objective-C.
Apache License 2.0
3.8k stars 293 forks source link

Promises in Application Extension #73

Closed richardtop closed 5 years ago

richardtop commented 5 years ago

Hi, is it possible to use Promises in Application Extensions (i.e. Siri Intents or Today Extension)? I'm using Promises for my network layer which is shared using a framework. The Promises library is used with the help of CocoaPods.

The app is organized in the following manner: AppNameKit - Core framework with networking and logic AppName - The application itelf AppIntent - The Siri intent AppIntentUI - The UI component of the Siri Intent.

While the framework is linked correctly and the app works fine, I got the error when I try to use the AppNameKit in AppIntent.

I can import Promises in the AppIntent, but whenever I use the code that actually uses Promise as its return value, I get the error:

ld: warning: linking against a dylib which is not safe for use in application extensions: /Users/richard/Library/Developer/Xcode/DerivedData/AppName-akvlogsasqbqhhgohvikypiqacwv/Build/Products/Debug-iphonesimulator/AppNameKit.framework/AppNameKit
ld: warning: Could not find auto-linked framework 'KeychainAccess'
ld: warning: Could not find auto-linked framework 'Kingfisher'
ld: warning: Could not find auto-linked framework 'Promises'
ld: warning: Could not find auto-linked framework 'FBLPromises'
ld: warning: Could not find auto-linked framework 'JWTDecode'
ld: warning: Could not find auto-linked framework 'Alamofire'
Undefined symbols for architecture x86_64:
  "static (extension in Promises):__C.OS_dispatch_queue.promises.getter : __C.OS_dispatch_queue", referenced from:
      default argument 0 of Promises.Promise.then(on: __C.OS_dispatch_queue, _: (A) throws -> ()) -> Promises.Promise<A> in PhoneBalanceIntentHandler.o
  "Promises.Promise.then(on: __C.OS_dispatch_queue, _: (A) throws -> ()) -> Promises.Promise<A>", referenced from:
      AppNameIntent.PhoneBalanceIntentHandler.handle(intent: AppNameKit.ViewBalanceIntent, completion: (AppNameKit.ViewBalanceIntentResponse) -> ()) -> () in PhoneBalanceIntentHandler.o
     (maybe you meant: _$S8Promises7PromiseC4then2on_ACyxGSo17OS_dispatch_queueC_yxKctFfA_)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

image

What could be the reason for such result? What is the best way to use Promises in such a configuration (shared networking & logic core, multiple targets - app, extension, intents...)?

Are Promises safe to be used in App Extensions?

shoumikhin commented 5 years ago

Hi Richard,

Promises are used in Google's app extensions. We don't use any app-specific APIs and have APPLICATION_EXTENSION_API_ONLY flags set in xcodeproj.

Your error looks like the lib is being missing during the linkage stage. Hope you were able to setup the project in such a way that Promises lib gets linked against your target.

Thanks.

richardtop commented 5 years ago

Hi Anthony, you were right - the library has ben linked against the common core, but hasn't been linked with the extension target.

After I've added the framework to the intent as a CocoaPod, I was able to successfully run the app. Hence, the issue was closed.

Btw, congratulations with the new role at Facebook.