I want to use NotificationCenter inside a watchOS target. But I get the following error message when building the app at import NotificationCenter:
NotificationCenter is not available when building for watchOS Simulator.
Consider using `#if !os(watchOS)` to conditionally import this framework.
How do you handle this situation? Can I no longer use the simulator?
Ok, I mixed things up. All I want to do in my watchOs framework was something like this:
NotificationCenter.default.post(...)
The class with import NotificationCenter was in the wrong framework. No need for such a class in a watchOs framework. So my problem is fixed.
Related
I am trying to call some functions of the Main app from the Notification Extension in the IOS app. To minimize the code changes, I am trying to import Notification Extension in the main app itself but I am getting an Undefined Symbol error in the main app.
objc[68450]: Class RSABSSATokenBlinder is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CryptoKitPrivate.framework/CryptoKitPrivate (0x15e118328) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CryptoKitCBridging.framework/CryptoKitCBridging (0x15b244400). One of the two will be used. Which one is undefined.
objc[68450]: Class RSABSSATokenWaitingActivation is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CryptoKitPrivate.framework/CryptoKitPrivate (0x15e118350) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CryptoKitCBridging.framework/CryptoKitCBridging (0x15b244428). One of the two will be used. Which one is undefined.
objc[68450]: Class RSABSSATokenReady is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CryptoKitPrivate.framework/CryptoKitPrivate (0x15e1183a0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CryptoKitCBridging.framework/CryptoKitCBridging (0x15b244478). One of the two will be used. Which one is undefined.
objc[68450]: Class RSABSSATokenIssuer is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CryptoKitPrivate.framework/CryptoKitPrivate (0x15e118418) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CryptoKitCBridging.framework/CryptoKitCBridging (0x15b2444f0). One of the two will be used. Which one is undefined.
I am building a basic SwiftUI app with CoreData. This warning shows up in console on Xcode 13.2.1. I have reinstalled Xcode, used App Store version as well as Xcode from apple developer website.
To reproduce this, create a new Xcode project for an iOS app. Run the app in an iPhone simulator.
I had the same problem running on the simulator. These 'warnings' disappeared when I ran on a device.
When creating an Intents.intentdefinition file, the generated Intent subclass source defines the class as:
#available(iOS 12.0, macOS 10.16, watchOS 5.0, *) #available(tvOS, unavailable)
#objc(OrderSoupIntent)
public class OrderSoupIntent: INIntent {}
But INIntent became available in iOS 10: https://developer.apple.com/documentation/sirikit/inintent
Why is the generated class iOS 12+ only? Can it be iOS 11+?
I found that custom intents was introduced in iOS 12. While I couldn't find in the SiriKit documentation, here's the WWDC video introducing the feature: https://developer.apple.com/videos/play/wwdc2018/211
Siri Shortcuts are a powerful new feature in iOS 12 that allow your app to expose its functionality to Siri.
RealityKit is only available on iOS 13.0 and up and when I try to integrate it to my project and run it on iOS 12.0 or below, the app crashes with abort_with_payload error.
I still want my app to run on iOS 9.0 - iOS 12.0 without the AR feature. Is there a way I can do that?
This happens because the framework RealityKit always imports even though the device does not have that framework. The solution is to make it optional based on the device you are using.
Go to you project's Build Settings.
Go to Linking -> Other linker Flags
Double click Other linker Flags values to add a new one.
Press add button then type -weak_framework RealityKit
That should do it. Enter then run your app.
Hope this helps. Happy Coding. :D
Have a look at the canImport(module) directive
#if canImport(RealityKit)
import RealityKit
#endif
#available(iOS 13.0, *)
class MyClassWhichUsesRealityKit {
func do() {
let v = ARView(frame: .zero)
}
}
Source: https://github.com/apple/swift-evolution/blob/master/proposals/0075-import-test.md
I have created a model class that I use in my iOS app and my Watch app - it is included in both targets. Now I have to use UIPasteboard in this class which is only available in UIKit, which is not available to watchOS. While I can import UIKit into this file without issue, when I go to use UIPasteboard it will not compile because the watch extension does not know about it.
How can I use UIPasteboard in a class that is available to my watch app?
I wondered if I could only run that code when the device isn't an Apple Watch by using #available, but this didn't resolve the issue.
if #available(iOS 7.0, *) {
UIPasteboard.generalPasteboard()...
//ERROR: Use of unresolved identifier 'UIPasteboard'
} else {
//don't use UIPasteboard
}
Use the existing preprocessor directive defined in Swift:
#if os(iOS)
//UIKit code here
#elseif os(watchOS)
//Watch code here
#endif
See the documentation for preprocessor directives here.
Maybe you could use an extension to factor out the UIPasteboard functionality and include the file containing the extension only in the iPhone target.
Ideally, code shared by several OS's should contain only truly shared code.
Also, if you want the conditionality, this is probably a cleaner way to do it.
There are two ways to do so.
First way is using preprocessor directives, like the following example:
#if os(iOS)
//Insert UIKit (iOS) code here
#elseif os(watchOS)
//Insert WatchKit (watchOS) code here
#endif
The second way is to determine if the code is called from the WatchKit Extension or iOS App. For example, you can set a global boolean flag to true before calling the code from WatchKit Extension, and false before calling from iOS App. Then the shared code can check the value of the flag to determine it is running on iOS or watchOS.