Worked on Xcode 10. Now in the beta I can't build I keep getting this error:
a "WatchKit" is not available when building for iOS Simulator.
Consider using #if !os(iOS) to conditionally import this framework.
I had the same issue for one swift file in the WatchKit Extension. It turned out that it was a member of both the iOS app and the WatchKit Extension. I unticked the iOS app in the target membership section for the file so that it only belongs to the WatchKit Extension target. Now the project builds successfully.
Some of the functionality to communicate between the Apple watch with the iPhone/iPad used to be implemented within the WatchKit framework. But at some point it got moved into the WatchKitConnectivity framework.
If you look in your Target's "Build Phase" -> "Link Binary With Libraries" section, you will see the "WatchKit.framework" with "Optional" status. iOS13+ has become more "strict" so it won't build unless I completely remove the "WatchKit.framework", and instead add "WatchConnectivity.framework".
Also make sure your iPhone/iPad code refers use "import WatchConnectivity" instead of "import WatchKit".
We need to use "Conditional Imports" to resolve the issue.
Replace the import WatchKit header with the below code :
#if !os(iOS)
import WatchKit
#endif
This resolved my issue and build successfully in iOS 13.
Xcode 11 removes WatchKit from the iOS SDK. From release notes:
The WatchKit framework is no longer included in the iOS SDK. If you’re using WatchKit APIs from iOS, you need to remove this use. The WatchKit framework remains available on watchOS. If you’re using WatchKit APIs from iOS to infer availability of features on the paired Apple Watch, include information about your use case when you submit feedback to Feedback Assistant. (49707950)
This includes Cordova plugins that reference WatchKit in plugin.xml:
<framework src="WatchKit.framework" />
The above line will add WatchKit as a framework for the iOS app target. You'll need to remove this and add WatchKit only to Watch target of your app.
Related
While archiving an iOS app on Xcode during the compilation phase;
I get the error -
"error: WatchKit App doesn't contain any WatchKit Extensions. Verify that the value of NSExtensionPointIdentifier in your WatchKit Extension's Info.plist is set to com.apple.watchkit." even though I have confirmed that this is set correct.
Then, why is this happening?
Thanks
Check build settings in watchappextension target if you have correct watch extension Info.plist file path. In my case, i had watch plist set.
I had similar issue. To solve that, I've modified the extension identifier so that it has watchkit's identifier as prefix. This is because, unless identifiers are prefix, those won't be allowed to embed on Xcode settings.
Check list:
In main iOS app settings on general tab, add your watchkit app in the embedded binaries section. Note that, if you ever deleted build folder, the embedded watchkit app may not be displayed in this section even if you just added there.
Make sure you see the watchkit app both in target dependancy & embedded binaries section. If not, add them on the build phases tab of your iOS app.
Now on settings of watchkit app, add your extension in the embedded binaries.
You should see the watchkit extension both in target dependancy & embedded binaries section. If not, add them on the build phases tab of your watchkit app.
On build settings of the extension, make sure bitcode is enabled. Base sdk should be latest iOS sdk.
See the watchkit app identifier is a prefix of the extension. I've renamed the product module (both for watchkit app & extension) to avoid spaces.
You should now be able to build or archive with proper mobile provisions. By the way, my Xcode version is 9.3.
Exit XCode, remove derived data, start XCode again and clean project
I am in the process of porting an all iOS + WatchOS 1 app written originally in Swift 1, to the latest Xcode 8, WatchOS 3, Swift 3.
My app has an embedded framework with some common functionality that used to compile and run file for both the watchkit extension target and the ios app target.
With Xcode 8 I can no longer seem to get this to work. When I try to import the framework in the watchkit extension code, I get the module not found error.
Is it still possible to compile and use one single embedded framework package on both the target iOS and WatchKit extension targets? In my framework I have the target platforms set to watchos, watchsimulator, iphoneos, iphonesimulator.
My gut says it's not possible anymore. Where originally all the code really ran on the phone itself, not that codes runs on the actual watch and the phone, you'd need to compile an embedded framework specifically for each.
Short version: You can't. Create a duplicate target and set it to use the watch SDK.
Longer version from Apple's docs: https://developer.apple.com/library/content/documentation/General/Conceptual/WatchKitProgrammingGuide/iOSSupport.html#//apple_ref/doc/uid/TP40014969-CH21-SW1
including:
NOTE
After you create a separate framework target for your WatchKit
extension, you must manage the contents of that framework separately
for both iOS and watchOS. If you add files to the iOS version of the
framework, remember to add them to the watchOS version.
Since Xcode 11 you can use Swift Package Manager to do this without duplicate targets. Have tested in Xcode 12 beta6 at least and it is another option to look at that didn't exist when the question was asked or I initially answered (and it doesn't meet the detailed requirements of the question as it needs newer Xcode).
I have a Cocoa Touch Framework that I developed for using in both my iOS app and my WatchKit app on iOS 8. I have no problems with iOS 8, however when I move the project to iOS 9 and update the WatchKit app to run natively I get the following error:
ParkFinderKit was rejected as an implicit dependency for 'ParkFinderKit.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'
I attempted to manually add watchossimulator and watchos to the list of supported platforms:
However this produces another error:
ParkFinderKit was rejected as an implicit dependency for 'ParkFinderKit.framework' because its SDK is platform 'com.apple.platform.iphonesimulator' and it needs to match platform 'com.apple.platform.watchsimulator'
Any ideas as to how to solve my issue?
Okay, it looks like you cannot use a Cocoa Touch Framework inside of a WatchKit app. I was able to get around this by creating a new Watch Framework target and then assigning each file from the original framework to the new framework in the Target Membership options.
This accomplishes my goal of sharing code between iOS and WatchKit without having duplicate code.
Currently, it is set to No for all targets: iOS app target, the WatchKit extension and the WatchKit app. Based on this post:
If you use Swift in your iPhone app, be sure to set the "Embedded Content Contains Swift" build setting to NO for your frameworks and extensions and YES for your iPhone app target.
I don't really understand what it does to my app. Do I have to change anything? I have read the document about "Embedded Content Contains Swift". I think this setting is only for apps that are built with both Objective-C and Swift. Am I correct?
By the way, in the linked frameworks and libraries of the iOS app target, I have: iAd, StoreKit and WatchKit. The WatchKit extension and app don't link to anything. I use Xcode 6.3.
Thanks for the help.
You only need to set the Embedded Content Contains Swift flag if you are adding a library or framework that contains Swift code, irrespective of your base-project's language (e.g., Swift or Objective-C).
More info here: https://developer.apple.com/library/ios/qa/qa1881/_index.html
For your situation, you don't have to set that flag to yes, as you are not linking to any external Swift libraries.
I have a watchkit target in my project. The problem I am facing is I don't need the watchkit target to be uploaded right now. I still want to keep the code however and don't want to delete all the files. Is there a way I can submit the App without the watch kit extension App? I thought about deleting the targets (not the files), but I don't know what is the best course of action in this situation. Can I tell itunesconnect not to include the watchkit App?
If you go to the target of your main app and remove the watchkit extension from "Embedded Binaries" it should remove your watchkit app.
To expand upon the answer from Tiago, remove the Watchkit Extension from "Embedded Binaries" and "Target Dependencies."
See Prevent deploying (disable) WatchKit App with iOS iPhone App in Xcode.