presentAudioRecordingControllerWithOutputURL not recognized in WatchKit project - ios

I have an existing project for WatchKit and with the new WatchOS release Apple have implemented a method called presentAudioRecordingControllerWithOutputURL to record audio from AppleWatch.
When I call this method I have two compilations errors. I imagine that I have to add or include something more but I don't know what I have to change in my project.
Errors:
/path/myProject WatchKit Extension/AWMessagesController.m:278:56: 'WKAudioRecordingPresetWideBandSpeech' is unavailable: not available on iOS
/path/myProject WatchKit Extension/AWMessagesController.m:277:11: 'presentAudioRecordingControllerWithOutputURL:preset:maximumDuration:actionTitle:completion:' is unavailable: not available on iOS

presentAudioRecordingControllerWithOutputURL cannot be used in an iOS extension. You have to migrate your code appropriately (e.g., copy files to the watch target). Refer to Apple's documentation.

Related

How to set APPLICATION_EXTENSION_API_ONLY on a Swift Package Manager (SPM) target?

Context:
We have an Xcode projet that builds an iOS app and a few app extensions.
We also have some shared code in Xcode frameworks, that have the flag APPLICATION_EXTENSION_API_ONLY on (so that we can use it in the app extensions).
We are currently in the process of modularising the app through SPM modules, and this implies converting these frameworks into SPM modules.
Problem:
The SPM module is not marked as app extension safe, and therefore a warning is emitted for every SPM module linked to an app extension, for each app extension (that makes quite a few warnings).
Comment:
I haven't found a way to set this flag on an SPM module.
The only thing I have found so far is a way to disable the warning completely, by setting the no_application_extension linker flag to the SPM target — but then I don't get any warning or error if I use an API unavailable in an app extension (I have tried to use UIApplication.shared in the module and I didn't get any warning or error; if I try to do that on my existing framework I immediately get a compiler error).
And if on the contrary I set the application_extension linker flag to the SPM target, then not only do I not get any warning or error either when using an API unavailable in app extensions, but I also get a whole lot of warnings when building the app, as many other frameworks that the app uses are not available for use in app extensions.
Question:
How do I get my SPM module to have the same behaviour as we used to have when setting the APPLICATION_EXTENSION_API_ONLY flag in the Xcode target?
This means:
not getting any warning when using in an app extension a module marked as safe for use in app extensions
while still getting an error when such module uses an API unavailable in app extensions
Ideally, there is a simple way to just set the APPLICATION_EXTENSION_API_ONLY flag on an SPM module and get back the familiar behaviour.
Thanks
Although I'm not sure about this, but I read something here that it'll be a pain to integrate everything using SPM
Basically as stated in the Xcode 13 beta 3 release notes:
Linking Swift packages from application extension targets or watchOS
applications no longer emits unresolvable warnings about linking to
libraries not safe for use in application extensions. This means that
code referencing APIs annotated as unavailable for use in app
extensions must now themselves be annotated as unavailable for use in
application extensions, in order to allow that code to be used in both
apps and app extensions. (66928265)
You can add the:
#available(iOSApplicationExtension, unavailable)
attribute to declarations using app extension unavailable APIs in order to get them to compile in a way that works for both apps and app extensions.

Swift youtube ios helper podfile 'sharedApplication' is unavailable: not available on iOS (App Extension)

After adding OneSignal to the project I get the following errors. I have tried Require Only AppExtension-Safe API to No in this pod file's settings and build successed but youtube pod file's functionality has broken, it does not open youtube videos after setting to no.
Could anyone give advice on how to solve this error? Thanks.
OneSignal target build phases.
It looks like you are building both an app and an app extension. An app extension is standalone, it doesn’t have access for example to the app delegate. Solution: Don’t try to use the app delegate. It won’t compile. Check what files you include in your app extension target. Don’t include files that use the app delegate.

Firebase IOS Crash Reporting with Embedded Framework

I have a project which contains 3 targets
The application target
The Embedded Framework
The today extension
Which target should I include the Firebase Crash Framework into ?
Currently I have included it into the embedded framework so that both the app and extension might use it.
The problem is that symbol files related to the application are not being uploaded automatically.
How do I get about this ?
Using the Firebase Crash SDK inside an Embedded framework and making the framework included in the App and the Today extension should work.
If you want to symbolicate the app related symbols, use the steps mentioned in https://firebase.google.com/docs/crash/ios#upload_symbol_files. This will enable the app/extension to have their symbols de-symbolicated.

Accessing a class of iPhone app in Watch App

I want to use my already developed NSObject Class in watch app (Watch App target is added to same project).
My iPhone App is written in Objective-C and now I am using Swift for Watch Extension, so I created a Bridge-Header to use this class in Watch App and add the class to Watch Extension target. When I build the app, it gives me many errors from other classes with this reason:
Cannot find interface declaration for UIControllerView, SuperClass of xxxxClass
And all these error files seem that they have a target of WatchKit Extension, but I didn't include them. On these files, Target Membership Watch Extension is also unchecked (means not a target of extension). Here are the Classes which I didn't added to Watch Extension, but they are running as a Watch Extension class.
You will need to select that class and check Target membership for WatchKit extension From file inspector.
For Swift class :
For Objective-C class you make it for .m file
You have the check the targeting files are added or not.
For that:
1.select your project file -->Build Phase-->Compile Sources.
-Check the file present or not.
2.if not just remove and add the files that are all missing in compile source.
3.Clean and Build your source..

How can I reference a Swift class in my WatchKit extension from the core iOS code?

I am trying to make my iOS application send the WatchKit Extension a set of data each time that data is updated from the server.
This is what the code in my iOS app looks like (names changed)
[WatchKitDataModel loadDataFromSource: currentData]
However, the iOS application does not recognize the WatchKitDataModel.
The error is "use of undeclared modifier."
Please help me make my apps talk to one another!
Ensure that your offending class is added to both the App target and the WatchKit target in the Document panel
The picture shows a TodayExtension but the principle is the same.
To share code between your WatchKit Extension and its containing app, create an embedded Framework in your app. Frameworks are the recommended tool by Apple to share code, within an app, and between apps.
To create an embedded Framework in Xcode 6, select your project and go to File > New > Target... Then in the dialog that opens select iOS > Framework & Library > Cocoa Touch Framework. Click Next. Give it a name, SomethingKit, similar to what Apple uses, e.g. UIKit, HealthKit, WatchKit. Now create your new classes and other common code in files inside your new Framework. When you want to use it in any of your other targets, i.e. the WatchKit Extension or its containing app, don't forget to import SomethingKit.
Ah, and don't forget to give public access level to the public-facing classes and functions in your Framework.
For more information about Frameworks to share code, for example, what sort of things cannot be included in Frameworks, see Apple's article: Using an Embedded Framework to Share Code.
There is also an interesting WWDC 2014 session video about this: Building Modern Frameworks.

Resources