When I added the widget extension to a multi-target project, the widget preview failed with an error saying Cannot preview in this file
.
As we all know, the widget was introduced in iOS 14.0, but my app's minimum deployment target is set to 13.0. I'm not sure whether this is the reason for the issue.
Here is the detailed error message:
== PREVIEW UPDATE ERROR:
FailedToLaunchAppError: Failed to launch com.company.AppName.WidgetName
==================================
| [Remote] LaunchError: Failed to launch widget extension
|
| ==================================
|
| | [Remote] NSError.CHSErrorDomain.1300: The operation couldn’t be completed. (CHSErrorDomain error 1300.)
| |
| | CHSErrorDomain (1300):
| | ==NSDebugDescription: extensionNotFound
This issue is most likely caused by environment configuration. I’ve read many articles and conducted numerous tests, but none of the methods worked.
Anyone knows how to deal with this problem?
Finally, I solved the problem, though it was a bit complicated. Some configurations may lead to memory problems, which can interfere with later tests if you don’t clear the DerivedData folder.
There are two places in main target that need to be modified to solve this issue — changing either one alone will not fix the problem.
In the Build Phases, the Run Script must be placed below Embed Foundation Extensions. You can put the Run Script at the bottom, just to be safe.
In the Embed Foundation Extensions section, you must uncheck “Copy only when installing”.