I’m trying to export an iOS Widget Extension as a CocoaPods library. Since adding a widget extension requires a target, I should create the target manually in the host project, then transfer the widget files to the repository. Therefore, the library will just vend raw files and not act as an extension.
First question: Am I right? Is there a way to save the whole extension in the repository?
Now the Podfile is:
target 'Example' do
use_frameworks!
# I need to create a `MyWidget` widget first
target 'MyWidgetExtension' do
inherit! :search_paths
pod 'WidgetIOSSDK', :path => '../'
end
end
In the widget entry point (MyWidgetBundle.swift
), I use the widget from the library:
import WidgetIOSSDK
@main
struct MyWidgetBundle: WidgetBundle {
var body: some Widget {
MyWidget2()
}
}
Build and run, the widget appears on the desktop. Then here is question 2:
- I can’t preview the SwiftUI if the file is not in the host project. (picture 1 below)
- Even if in the host project I create a blank SwiftUI file and in the preview section I use the view from the pod library, it doesn’t work either.(picture 2 below)
error: No candidates found to host preview
error: MyWidgetExtension may have crashed
if the log will do any help:
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Incident Identifier: 78D3F9E1-A7D0-4707-8D8F-59D7BD560036
CrashReporter Key: 27F89101-C142-7992-630D-C7F6B5D98948
Hardware Model: Mac14,3
Process: AccessibilityControlsExtension [83222]
Path: /Volumes/VOLUME/*/AccessibilityUIServer.app/PlugIns/AccessibilityControlsExtension.appex/AccessibilityControlsExtension
Identifier: com.apple.AccessibilityUIServer.AccessibilityControlsExtension
Version: 1.0 (1)
Code Type: ARM-64 (Native)
Role: Unspecified
Parent Process: launchd_sim [6261]
Coalition: com.apple.CoreSimulator.SimDevice.66E9BC5C-2BA2-445D-924F-7B7103BED25A [1053]
Responsible Process: SimulatorTrampoline [6244]
Date/Time: 2024-12-25 15:53:12.8953 +0800
Launch Time: 2024-12-25 15:53:12.6843 +0800
OS Version: macOS 15.1.1 (24B91)
Release Type: User
Report Version: 104
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001cd645168
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [83222]
Triggered by Thread: 0
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 ExtensionFoundation 0x1cd645168 -[_EXConnectionHandlerExtension willFinishLaunching] + 912
1 ExtensionFoundation 0x1cd61ded4 -[_EXRunningExtension willFinishLaunching] + 212
2 ExtensionFoundation 0x1cd61da68 -[_EXRunningExtension resume] + 40
3 ExtensionFoundation 0x1cd61d98c -[_EXRunningExtension startWithArguments:count:] + 392
4 ExtensionFoundation 0x1cd62fec8 EXExtensionMain + 216
5 Foundation 0x180f74ba4 NSExtensionMain + 176
6 dyld_sim 0x10255d410 start_sim + 20
7 dyld 0x10243a274 start + 2840
Thread 1:
0 libsystem_pthread.dylib 0x1022a292c start_wqthread + 0
Thread 2:
0 libsystem_pthread.dylib 0x1022a292c start_wqthread + 0
Thread 0 crashed with ARM Thread State (64-bit):
x0: 0x0000600001700580 x1: 0x00000001f1993b77 x2: 0x00000001ec0386d8 x3: 0x0000000000000033
x4: 0x0000000102705590 x5: 0x0000000000000013 x6: 0x0000000000000000 x7: 0x0000000000000000
x8: 0x000000007fffffff x9: 0x000000007fffffff x10: 0x0000600001700940 x11: 0x0000000000000003
x12: 0x0000000000000003 x13: 0x0000600001700960 x14: 0x00000001ec0386d8 x15: 0x00000001ec0386d8
x16: 0x00000001ec0386d8 x17: 0x000000018017835c x18: 0x0000000000000000 x19: 0x0000600001700580
x20: 0x0000600001704ec0 x21: 0x0000000000000000 x22: 0x0000000000000000 x23: 0x0000600001700780
x24: 0x0000600000c04ae0 x25: 0x0000000000000000 x26: 0x00000001ee61d000 x27: 0x0000000000000000
x28: 0x0000000000000000 fp: 0x000000016dbba130 lr: 0x00000001cd645168
sp: 0x000000016dbba0d0 pc: 0x00000001cd645168 cpsr: 0x60001000
far: 0x0000000000000000 esr: 0xf2000001 (Breakpoint) brk 1
Binary Images:
0x102434000 - 0x1024b7fff dyld (*) <6beafde4-b011-3e47-8aae-4d7b6e4bb7e8> /usr/lib/dyld
0x102244000 - 0x10224bfff com.apple.AccessibilityUIServer.AccessibilityControlsExtension (1.0) <a67e159b-253d-306c-b6fb-dd3fec38bd0f> /Volumes/VOLUME/*/AccessibilityUIServer.app/PlugIns/AccessibilityControlsExtension.appex/AccessibilityControlsExtension
0x10255c000 - 0x10259ffff dyld_sim (*) <e3f44485-3ed0-37c0-a68c-d2e246261b3d> /Volumes/VOLUME/*/dyld_sim
0x1022fc000 - 0x102303fff libsystem_platform.dylib (*) <119b4ee6-698b-34e6-8c01-a47c12fa79ff> /usr/lib/system/libsystem_platform.dylib
0x10231c000 - 0x102357fff libsystem_kernel.dylib (*) <69036356-4efc-3e8c-bdc5-1d867464a72b> /usr/lib/system/libsystem_kernel.dylib
0x1022a0000 - 0x1022affff libsystem_pthread.dylib (*) <9edd360a-2793-3746-86c8-7428b49f96a1> /usr/lib/system/libsystem_pthread.dylib
0x1cd617000 - 0x1cd6c8fff com.apple.ExtensionFoundation (97) <4bde6263-c68e-3f49-9caa-a8230b10c66b> /Volumes/VOLUME/*/ExtensionFoundation.framework/ExtensionFoundation
0x1807d8000 - 0x181428fff com.apple.Foundation (6.9) <d10a658f-43ab-384f-b207-60969a8b5b45> /Volumes/VOLUME/*/Foundation.framework/Foundation
0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???
0x180175000 - 0x1801b9fff libdispatch.dylib (*) <76a67435-58c9-3af9-9d46-02ab7161baeb> /Volumes/VOLUME/*/libdispatch.dylib
EOF