<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>ImportFromDevicesCommands &#8211; Wade Tregaskis</title>
	<atom:link href="https://wadetregaskis.com/tags/importfromdevicescommands/feed/" rel="self" type="application/rss+xml" />
	<link>https://wadetregaskis.com</link>
	<description></description>
	<lastBuildDate>Thu, 22 Aug 2024 23:35:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wadetregaskis.com/wp-content/uploads/2016/03/Stitch-512x512-1-256x256.png</url>
	<title>ImportFromDevicesCommands &#8211; Wade Tregaskis</title>
	<link>https://wadetregaskis.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">226351702</site>	<item>
		<title>&#8220;Import from iPhone or iPad&#8221; doesn&#8217;t work when any view contains a SwiftUI Toggle</title>
		<link>https://wadetregaskis.com/import-from-iphone-or-ipad-doesnt-work-when-any-view-contains-a-swiftui-toggle/</link>
					<comments>https://wadetregaskis.com/import-from-iphone-or-ipad-doesnt-work-when-any-view-contains-a-swiftui-toggle/#respond</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Thu, 22 Aug 2024 23:22:42 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Bugs!]]></category>
		<category><![CDATA[Continuity Camera]]></category>
		<category><![CDATA[Import from iPhone or iPad]]></category>
		<category><![CDATA[importableFromServices]]></category>
		<category><![CDATA[ImportFromDevicesCommands]]></category>
		<category><![CDATA[Sad]]></category>
		<category><![CDATA[SwiftUI]]></category>
		<category><![CDATA[Toggle]]></category>
		<guid isPermaLink="false">https://wadetregaskis.com/?p=8371</guid>

					<description><![CDATA[This is a public reposting of FB14893699, in case it’s helpful to anyone else or especially in case someone else has seen this too and knows how to work around it. If any view in the [active] window contains a Toggle &#8211; even one that’s disabled or hidden &#8211; then Continuity Camera (re. ImportFromDevicesCommands and&#8230; <a class="read-more-link" href="https://wadetregaskis.com/import-from-iphone-or-ipad-doesnt-work-when-any-view-contains-a-swiftui-toggle/" data-wpel-link="internal">Read more</a>]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p>This is a public reposting of FB14893699, in case it’s helpful to anyone else or especially in case someone else has seen this too and knows how to work around it.</p>
</div></div>



<p>If <em>any</em> view in the [active] window contains a <a href="https://developer.apple.com/documentation/swiftui/toggle" data-wpel-link="external" target="_blank" rel="external noopener"><code>Toggle</code></a> &#8211; even one that’s disabled or hidden &#8211; then Continuity Camera (re. <code><a href="http://ImportFromDevicesCommands" data-wpel-link="external" target="_blank" rel="external noopener">ImportFromDevicesCommands</a></code> and <code><a href="https://developer.apple.com/documentation/scenekit/sceneview/4049460-importablefromservices" data-wpel-link="external" target="_blank" rel="external noopener">importableFromServices</a></code>) doesn’t work; all the submenu items under “Import from iPhone or iPad” are disabled.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="412" height="309" src="https://wadetregaskis.com/wp-content/uploads/2024/08/22import-from-iphone-or-ipad22-disabled.webp" alt="Screenshot of the File menu with the &quot;Import from iPhone or iPad&quot; submenu expanded, and all items therein are disabled." class="wp-image-8372" srcset="https://wadetregaskis.com/wp-content/uploads/2024/08/22import-from-iphone-or-ipad22-disabled.webp 412w, https://wadetregaskis.com/wp-content/uploads/2024/08/22import-from-iphone-or-ipad22-disabled-256x192.webp 256w, https://wadetregaskis.com/wp-content/uploads/2024/08/22import-from-iphone-or-ipad22-disabled@2x.webp 824w" sizes="(max-width: 412px) 100vw, 412px" /></figure>
</div>


<p>I don’t know if this is truly specific to <code>Toggle</code>, that’s just the example case I happen to have isolated [first?].</p>



<p>What’s really weird is that once a <code>Toggle</code> has <em>ever</em> been displayed, even if you subsequently remove it from the view hierarchy entirely the “Import from iPhone or iPad” submenu items all remain disabled.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled" data-code-block-pro-font-family="" style="font-size:.875rem;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #AF00DB">import</span><span style="color: #000000"> </span><span style="color: #267F99">SwiftUI</span></span>
<span class="line"></span>
<span class="line"><span style="color: #0000FF">@main</span></span>
<span class="line"><span style="color: #0000FF">struct</span><span style="color: #000000"> </span><span style="color: #267F99">Example</span><span style="color: #000000">: App {</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #0000FF">@State</span><span style="color: #000000"> </span><span style="color: #0000FF">var</span><span style="color: #000000"> breakImportFromiDevice = </span><span style="color: #0000FF">true</span></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #0000FF">@State</span><span style="color: #000000"> </span><span style="color: #0000FF">var</span><span style="color: #000000"> text = </span><span style="color: #A31515">&quot;&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #000000">    </span><span style="color: #0000FF">var</span><span style="color: #000000"> body: some Scene {</span></span>
<span class="line"><span style="color: #000000">        WindowGroup {</span></span>
<span class="line"><span style="color: #000000">            VStack {</span></span>
<span class="line"><span style="color: #000000">                </span><span style="color: #795E26">TextField</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;Input&quot;</span><span style="color: #000000">, </span><span style="color: #795E26">text</span><span style="color: #000000">: $text) </span><span style="color: #008000">// Doesn&#39;t break anything.</span></span>
<span class="line"></span>
<span class="line"><span style="color: #000000">                </span><span style="color: #AF00DB">if</span><span style="color: #000000"> breakImportFromiDevice {</span></span>
<span class="line"><span style="color: #000000">                    </span><span style="color: #795E26">Toggle</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;Break import from iDevice&quot;</span><span style="color: #000000">, </span><span style="color: #795E26">isOn</span><span style="color: #000000">: $breakImportFromiDevice)</span></span>
<span class="line"><span style="color: #000000">                }</span></span>
<span class="line"><span style="color: #000000">            }</span></span>
<span class="line"><span style="color: #000000">            .</span><span style="color: #795E26">importableFromServices</span><span style="color: #000000">(</span><span style="color: #795E26">action</span><span style="color: #000000">: { (</span><span style="color: #795E26">images</span><span style="color: #000000">: [NSImage]) -&gt; </span><span style="color: #267F99">Bool</span><span style="color: #000000"> </span><span style="color: #AF00DB">in</span></span>
<span class="line"><span style="color: #000000">                </span><span style="color: #795E26">print</span><span style="color: #000000">(</span><span style="color: #A31515">&quot;Load image!&quot;</span><span style="color: #000000">)</span></span>
<span class="line"><span style="color: #000000">                </span><span style="color: #AF00DB">return</span><span style="color: #000000"> </span><span style="color: #0000FF">true</span></span>
<span class="line"><span style="color: #000000">            })</span></span>
<span class="line"><span style="color: #000000">        }.</span><span style="color: #001080">commands</span><span style="color: #000000"> {</span></span>
<span class="line"><span style="color: #000000">            </span><span style="color: #795E26">ImportFromDevicesCommands</span><span style="color: #000000">()</span></span>
<span class="line"><span style="color: #000000">        }</span></span>
<span class="line"><span style="color: #000000">    }</span></span>
<span class="line"><span style="color: #000000">}</span></span>
<span class="line"></span></code></pre></div>



<p>There are some circumstances in which this gets “unbroken” during interactions with other views and so forth, which is 100% reproducible in my real app but I have no idea what the reason is.  The steps involved in my real app are kinda ridiculous (and not in any way remotely a viable workaround) and make absolutely no sense &#8211; it only “unbreaks” when a specific view is in a specific weird state (itself kind of the result of a bug, albeit a benign one).  And that weird state is merely whether it’s displaying one image or another &#8211; which as far as SwiftUI is concerned is not even a difference in view state, since I’m just swapping <code><a href="https://developer.apple.com/documentation/appkit/nsimage" data-wpel-link="external" target="_blank" rel="external noopener">NSImage</a></code>s under the cover.</p>



<p>I figured it must be something to do with view focus, but after much experimentation I believe I can conclusively rule that out.  No matter which view has focus, or how focus is configured, or which views are even focusable at all, the problem persists.  Likewise for window focus and key state.  And, [accessability-]focusable views other than <code>Toggle</code> &#8211; e.g. <code><a href="https://developer.apple.com/documentation/swiftui/textfield" data-wpel-link="external" target="_blank" rel="external noopener">TextField</a></code> &#8211; don’t cause any issues.</p>



<p>Frankly it&#8217;s baffling, and a mite infuriating.  I can&#8217;t even conceive of how SwiftUI can be so incredibly broken regarding such basic functionality, and the apparent interaction of GUI elements that have absolutely no business together.</p>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-dots"/>



<p>Tangentially, a few things I&#8217;ve noticed about this Continuity Camera feature:</p>



<ul class="wp-block-list">
<li>&#8220;Add Sketch&#8221; doesn&#8217;t do anything.  Unlike the other options, which open the camera app on the target iDevice, it has no effect. 🤷‍♂️</li>



<li>Within the Finder, you can right-click empty whitespace within a folder, and the contextual menu has this &#8220;Import from iPhone or iPad&#8221; option at the bottom.  That&#8217;s pretty handy &#8211; until now I&#8217;d been doing it the &#8220;hard&#8221; way by taking a photo on my iPhone and AirDropping it across to my Mac.<br><br>I&#8217;d never noticed that feature prior to debugging this problem (I wanted to confirm that multiple other apps worked just fine; that it wasn&#8217;t an issue with Continuity Camera system-wide).</li>



<li>TextEdit has the same feature but tweaks the wording to &#8220;Insert…&#8221; rather than &#8220;Import…&#8221;, which I thought is both a nice touch and frustratingly not something you can do in your own apps (at least, not in SwiftUI). 😕</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://wadetregaskis.com/import-from-iphone-or-ipad-doesnt-work-when-any-view-contains-a-swiftui-toggle/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			<media:content url="https://wadetregaskis.com/wp-content/uploads/2024/08/22import-from-iphone-or-ipad22-disabled.webp" medium="image" />
<post-id xmlns="com-wordpress:feed-additions:1">8371</post-id>	</item>
	</channel>
</rss>
