<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jon Gary on Medium]]></title>
        <description><![CDATA[Stories by Jon Gary on Medium]]></description>
        <link>https://medium.com/@jongary?source=rss-c5073b85b624------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*IXa3_gGqMgWVsdGE.jpeg</url>
            <title>Stories by Jon Gary on Medium</title>
            <link>https://medium.com/@jongary?source=rss-c5073b85b624------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:27:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jongary/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Updates On My iOS apps]]></title>
            <link>https://medium.com/@jongary/updates-on-my-ios-apps-9384b20a68f7?source=rss-c5073b85b624------2</link>
            <guid isPermaLink="false">https://medium.com/p/9384b20a68f7</guid>
            <category><![CDATA[ios-apps]]></category>
            <category><![CDATA[photography]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[audio]]></category>
            <dc:creator><![CDATA[Jon Gary]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 15:03:09 GMT</pubDate>
            <atom:updated>2021-02-02T15:03:09.432Z</atom:updated>
            <content:encoded><![CDATA[<p>While my user base is tiny, I like to “keep my whistle wet” in retirement, so I’ve recently completed updates on my three iOS apps. All of my apps address a use case I had myself, and I hope others will find them useful.</p><h4>Playertronic 2.1</h4><p>My first update is to my audio player app <a href="https://apps.apple.com/us/app/playertronic/id1478900125">Playertronic</a>, which I originally wrote about <a href="https://medium.com/@jongary/playertronic-2-0-the-ios-audio-player-for-musicians-3287651604b1">here</a>. In the 2.1 update I’ve added a parametric EQ, and improved accessibility.</p><figure><img alt="A screen shot of the app showing the sliders for a three band equalizer with low, mid-range, and high frequency controls." src="https://cdn-images-1.medium.com/max/370/1*70EtOpom_YSuNNqC04LW8A.png" /><figcaption>Playertronic’s three-band EQ.</figcaption></figure><h4>Panotronic 1.4</h4><p><a href="https://apps.apple.com/us/app/panotronic/id1465731693">Panotronic</a> is an app that makes panoramic photos easier to share, especially to Instagram, where the aspect ratio limitations are a problem. The initial version of the app just sliced photos into squares. Version 1.4 adds the ability to share a video that pans across the panorama, as well as improved accessibility.</p><figure><img alt="A screenshot showing a movie player, controls for the starting position for the video, the resolution, and duration." src="https://cdn-images-1.medium.com/max/370/1*SsujcWgAJs4IaSh_f7U_kA.png" /></figure><h4>Phototronic Metadata 1.2</h4><p>This app provides an action extension allowing you to browse metadata embedded in photos. <a href="https://apps.apple.com/us/app/phototronic-metadata/id1474827268">Version 1.2</a> adds a feature to copy any metadata item (metadatum?), or all of the metadata so you can paste into a document, or email, or whatever.</p><figure><img alt="A screenshot showing summary of a photo’s metadata including date taken, image size, and camera model." src="https://cdn-images-1.medium.com/max/370/1*v31UFtBUqvwIYdosbHBEWQ.png" /><figcaption>The top level view of a photo’s metadata.</figcaption></figure><h4>Colophon</h4><p>While I’ve retired from full-time software engineering, there is still creative satisfaction in solving little problems with code. Plus, programming can be fun, especially when you can do whatever you want. I’m looking forward to getting an M1 mac and continue making music, art, and apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9384b20a68f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binding a SwiftUI Slider to an AVPlayer’s time.]]></title>
            <link>https://medium.com/@jongary/binding-a-swiftui-slider-to-an-avplayers-time-a9660526170a?source=rss-c5073b85b624------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9660526170a</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[avfoundation]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Jon Gary]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 18:10:54 GMT</pubDate>
            <atom:updated>2020-07-13T18:21:55.494Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently decided to learn Swift UI by porting my application Playertronic from UIKit. I wrestled a bit with how to implement a slider to scrub through the audio file. My UIKit implementation used state stored in the view controller layer to select between the current playback time and the user-selected time while the slider was being interacted with, while displaying the time in the same view on screen. Some others I’ve seen online trying to do the same were struggling as well.</p><p>The approach I came up with uses a ObservableObject to wrap an AVPlayer. This class publishes a property called displayTime, which represents the playback time, unless the Slider is active. The Slider is bound to the player.displayTime property, and the slider&#39;s action sets a scrubControl property on the player so it can avoid updating displayTime during the scrub (when the value is set by the binding).</p><h3>Slider</h3><p>In ContentView</p><pre>Slider(value: self.$player.displayTime, in: (0...self.player.itemDuration), onEditingChanged: { (scrubStarted) in <br>   if scrubStarted { <br>      self.player.scrubState = .scrubStarted <br>   } else { <br>      self.player.scrubState = .scrubEnded(self.player.displayTime)   <br>   } <br>})</pre><h3>scrubControl</h3><pre>var scrubState: PlayerScrubState = .reset { <br>   didSet { <br>      switch scrubState { <br>      case .reset: return <br>      case .scrubStarted: return <br>      case .scrubEnded(let seekTime): avPlayer.seek(to: CMTime(seconds: seekTime, preferredTimescale: 1000)) <br>      }<br>   }<br>}</pre><h3>Time observation</h3><pre>switch self.scrubState {<br>case .reset:<br>   self.displayTime = time.seconds<br>case .scrubStarted:<br>    // When scrubbing, the displayTime is bound to the Slider view, so<br>    // do not update it here.<br>    break<br>case .scrubEnded(let seekTime):<br>    self.scrubState = .reset<br>    self.displayTime = seekTime<br>}</pre><p>The attached project illustrates this approach. I really like SwiftUI and Combine and look forward to rewiring my brain to use them effectively.</p><p>PS: The embedded audio file was my first GarageBand creation from 15 years ago!</p><p><em>Originally published at </em><a href="https://github.com/jongary/SwiftUIAVPlayer/blob/master/README.md"><em>https://github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9660526170a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playertronic 2.0, the iOS audio player for musicians.]]></title>
            <link>https://medium.com/@jongary/playertronic-2-0-the-ios-audio-player-for-musicians-3287651604b1?source=rss-c5073b85b624------2</link>
            <guid isPermaLink="false">https://medium.com/p/3287651604b1</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[quarantine]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[audio]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jon Gary]]></dc:creator>
            <pubDate>Mon, 30 Mar 2020 15:46:57 GMT</pubDate>
            <atom:updated>2020-04-02T01:33:32.741Z</atom:updated>
            <content:encoded><![CDATA[<p><em>I’m using some of my time stuck at home during COVID-19 quarantine to rework my </em><a href="https://apps.apple.com/us/app/playertronic/id1478900125"><em>Playertronic</em></a><em> app, and version 2 is now available, but you can still be a tester for future releases by request via Twitter DM to </em><a href="https://twitter.com/Playertronic1"><em>@Playertronic1</em></a><em>. Include your email in your message to be added.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gs-ogsUVGMQ-J3Q7Aml2FQ.png" /><figcaption>Playertronic icon</figcaption></figure><p>If you’re in one or more bands like I am, you wind up passing around a lot of audio recordings from rehearsals, studio sessions, and those song ideas you or your band-mates created in Voice Memos. If you’re also like me, you don’t want to add most of these files to your library of commercially available music in iTunes/Apple Music just so you can hear them on your iPhone. I created Playertronic to address these use cases based on my own needs.</p><p>Version 1.0, which I published last year, offered only a single list. Working with multiple sets of tracks required removing all the tracks in the app and adding the new ones. This was good enough for my use, but not good enough for musicians who work with many groups or who have big repertoires for events like corporate parties, weddings, bar mitzvahs, etc. Others who do a lot of ad-hoc audio file sharing and review, such as journalists, may also find the app useful.</p><h3>Use cases</h3><h4>Rehearsing new material</h4><p>The band is working on new tunes, and one of you records the tunes with Voice Memos. After rehearsal, the Voice Memos are emailed to you. You want to rehearse the new tunes. You open the emails, tap on each audio attachment, tap the share button, and select “Copy to Playertonic”. In the app, you create a new playlist to add the songs to and. You open the playlist and play each tune on repeat so you can practice it.</p><h4>Building set lists</h4><p>You have 75 tunes in your master playlist, but you need to organize a 45-minute set. You create a playlist for the set, and add the tracks you want until the playlist duration is about 45 minutes. You open the playlist for the set and put the songs in the order you want to perform them in.</p><h4>Organizing interviews</h4><p>Your thesis project involves interviewing interviewing medical students multiple times over the course of their internships. Some of the audio is in your Voice Memos, others were recorded by other grad students, and they stored them in Google Drive. You share each file to Playertronic, where you create a playlist for each student and add their interview recordings to their playlist.</p><h4>The non-use case</h4><p><a href="https://apps.apple.com/us/app/playertronic/id1478900125">Playertronic</a> is not intended to replace Apple Music’s library, and is not intended to scale to your 100 gigabyte record-junkie MP3 collection.</p><p>Maybe version 3.</p><h3>Version 1 features</h3><p>As I said, version 1 was drop-dead simple, but let’s go through the features to highlight what’s new in version 2.</p><p>Features included:</p><ul><li>Add files from file providers (Dropbox, iCloud, Google Drive), Share button, AirDrop.</li><li>Reorder tracks.</li><li>Scrubber for seeking within tracks.</li><li>Trash button removes all tracks.</li></ul><figure><img alt="Screen shot of Version 1. A single list of music files." src="https://cdn-images-1.medium.com/max/320/1*vBEdDMCygTx7PUv3ifI2-Q@2x.jpeg" /><figcaption>Version 1: a single playlist. That’s it.</figcaption></figure><h3>Version 2 features</h3><ul><li>Multiple playlists</li><li>Automatically generate playlists from album tags when importing</li><li>Duration and track count display for playlists, which is handy when building set lists for gigs.</li><li>Repeat mode for tracks and playlists</li><li>Volume control.</li></ul><h4>Managing Playlists</h4><p>These screenshots illustrate the new user interface. The Master playlist is the list of all tracks and is always present. Tracks “live” in the master playlist, and you remove them there to delete them from the library completely. The other playlists share a subset of the tracks in the master playlist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*atMBu48hbyRMIsyHf5jKUg.png" /><figcaption>Version 2. Multiple playlists and transport toolbar</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*RGENbB2M7XNGIljc3q9f0A.png" /><figcaption>Swipe left to remove or rename a playlist.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*LAY9i3FGJEz1gjFAe5105Q.png" /><figcaption>Playlist view with current track indicator</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*iSwb2bUk-goHMJHREQ6oog.png" /><figcaption>Swipe left to remove a track or reassign a track to other playlists.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*INunPXtbSqwVLXsPHmIfLw.png" /><figcaption>Assign a track to multiple playlists.</figcaption></figure><h4>Repeating tracks and playlists</h4><p>Repeating tracks and playlists are helpful for practicing music.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*PSP3HcE9lw_0-OKAG-nbPw.png" /><figcaption>Swipe right to play or repeat a track. The repeat button at the top repeats the whole list.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*Hl7aOTV5bIEzoW6y7KHxtA.png" /><figcaption>Swipe right to play a playlist once or repeating.</figcaption></figure><h4>Scrubbing and volume controls</h4><p>The toolbar is a small space, so I kept only the most essential playback controls there. Tapping on the toolbar (e.g. on the song title) presents a view with more controls and information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*5z9JWJGXnqJArjl8mJJgAg.png" /><figcaption>Player controls with scrubber and volume.</figcaption></figure><h3>Last thoughts</h3><h4>Saying it out loud</h4><p>If you’re a solo developer creating your own apps, you can develop a few blind spots. Writing this up helped me spot a few issues in the app, and helped me identify features for future versions.</p><p>The app <a href="https://apps.apple.com/us/app/playertronic/id1478900125">is available here</a> (though currently just 1.0. Updates are free).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3287651604b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logitech Slim Combo for iPad Pro 12.9 (1st generation) mini Review]]></title>
            <link>https://medium.com/@jongary/logitech-slim-combo-for-ipad-pro-12-9-1st-generation-mini-review-3e4abceb1270?source=rss-c5073b85b624------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e4abceb1270</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[review]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ipad]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Jon Gary]]></dc:creator>
            <pubDate>Mon, 26 Aug 2019 20:27:33 GMT</pubDate>
            <atom:updated>2019-08-26T20:27:33.312Z</atom:updated>
            <content:encoded><![CDATA[<p>After my Apple Smart Keyboard cover (the old one, not the newer folio) gave up the ghost, I decided to find something better to replace it. After looking at the options, I settled on the Logitech Slim Combo. It connects using the same magnetic smart connector as the Apple Smart Keyboard cover.</p><p>Unlike the Apple product, the Slim Combo includes a hard plastic rear cover, with a continuously adjustable kickstand that works with or without the keyboard connected. It’s much more robust and usable than the maddening, flappy origami-based Apple Smart Keyboard Cover. The rear cover includes an elastic sleeve to stow an Apple pencil, or whatever similarly-sized cylindrical object you need stuck to your iPad.</p><p>The keyboard itself is very good, actually better than any Apple laptop keyboard currently shipping. It’s backlit, has a bunch of function keys, and because it draws power from the iPad via the smart connector, never needs charging. The backlighting is adjustable via function keys. The other function keys control media playback, screen brightness, invoke search, go to the home screen, and lock the iPad.</p><p>It’s not all good news however. The keyboard has a number of function keys in critical locations.</p><ul><li>The lock key, which locks the iPad, is directly above the delete key, making accidental locking all too easy. That’s no fun at all.</li><li>* The keyboard switching key in the lower-left corner is easy to hit when typing with the folding palm rest is folded under the keyboard, accidentally invoking the emoji on-screen keyboard.</li></ul><p><a href="https://www.logitech.com/en-us/product/slimcombo">https://www.logitech.com/en-us/product/slimcombo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e4abceb1270" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Panotronic]]></title>
            <link>https://medium.com/@jongary/making-panotronic-7309db2bdefb?source=rss-c5073b85b624------2</link>
            <guid isPermaLink="false">https://medium.com/p/7309db2bdefb</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[instagram]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jon Gary]]></dc:creator>
            <pubDate>Thu, 04 Jul 2019 21:42:18 GMT</pubDate>
            <atom:updated>2019-07-05T21:23:08.342Z</atom:updated>
            <content:encoded><![CDATA[<p>In June of 2018, I left Twitter after a 5 year stint, the most recent gig in my 30+ year career. I found I had lost my enthusiasm for software development, and I was a bit burned out by technology churn and the endless array of frustrating, unreliable tools so many of us deal with.</p><p>After a year of not doing any software development, I found myself wanting an app for a single purpose: to slice up panoramic photos into a set of squares to post as a set on Instagram in order to take advantage of the swiping feature they have for multiple photo posts. This provides a better panoramic experience. I knew this would be a simple programming task, so why not blow the dust off of Xcode and crank it out. The result is <a href="https://t.co/US5HVdiWtZ">Panotronic, available here.</a></p><p>Would building this app draw me back into the life of a full-time software engineer, or send me retreating to my art and music?</p><p>Read on…</p><h3>The Icon</h3><p>Step one of every project is the icon and the t-shirt, right? <a href="https://www.redbubble.com/people/jongary/works/39857887-panotronic?body_color=purple&amp;p=womens-fitted-scoop&amp;print_location=front&amp;ref=available_products_swiper&amp;size=medium#&amp;gid=1&amp;pid=1">Pick one up if you like!</a></p><p>I wanted the icon to visually communicate the action of the app. I also wanted some visual connection to Instagram’s app icon without copying anything, so I chose colors in the gradient are close to those in Instagram’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*GGokMiHt5ykcEUp7jcExVA.png" /><figcaption>The icon</figcaption></figure><h3>Version 1</h3><p>Version 1 of Panotronic is a simple collection of photos showing only the images in the Panoramas smart album of the Photos library. I found <a href="https://developer.apple.com/documentation/photokit/browsing_and_modifying_photo_albums">Apple sample code</a> to base my photo collection view on.</p><p>Tapping on an image displays the wide format image cut up into square images equally dividing the width by the height. The video below demonstrates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*A-sKetKyszqKlydrQrr4Gg.png" /><figcaption>Panorama chopped into 4 square photos</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FflQe4SYNVp8%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DflQe4SYNVp8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FflQe4SYNVp8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/be2ca2e5b38eab8dd163fa6df2614302/href">https://medium.com/media/be2ca2e5b38eab8dd163fa6df2614302/href</a></iframe><h3>On-boarding</h3><p>Accessing the user’s photos requires their permission. iOS developers know this needs to be a two step process. Just throwing up the system-provided permissions prompt at the time of access is disorienting, and can lead to denials before the user understands what’s happening. Recovering from that misstep requires the user visiting the Settings app and navigating within that, so all developers want to avoid that burdensome scenario.</p><p>It is easy to detect the need to request authorization to access Photos. When I do, I launch the app into a welcome view before the photo collection. I display this view on first run, or if photo access is not authorized. I leave this welcome view in the navigation stack throughout the first launch of the app, which lets the user revisit the welcome text. Subsequent launches go directly to the photo collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*jMQ9C7Lcl_W4aNvwRxzJiA.jpeg" /><figcaption>Welcome view prompting to ask for authorization</figcaption></figure><h3>The Good Parts</h3><p>I did have the pleasure of a simple, constrained task of my own conception and a clean sheet to start with, so some of the frustrations of development (e.g. dealing with Other People’s Stuff™) were avoided.</p><h4>Pure Swift</h4><p>I really disliked working in a mixed Swift/Objective-C code base in the past. This was my first app 100% in Swift, and aside from debugging issues, it was a good experience. I used structs, and enums, and Swift error handling in my models and interfaces, and I didn’t go too crazy with nested trailing closures with those $-prefixed variables which lead to unreadable, overly dense source code.</p><h4>Code signing, profiles, etc.</h4><p>I used all of the automatic workflows for signing, profiles, uploading to the AppStore, etc. I was pleasantly surprised at how easy this has become, so good job on that front, Apple.</p><h3>Bumps in the road</h3><p>The app was simple, but not quite what I envisioned.</p><h4>Sharing from Panotronic to Instagram</h4><p>If you watched the demo movie above, you might ask why not use the standard share sheet to allow the user to share the square photos directly to Instagram? That’s what I wanted to do, but Instagram doesn’t accept more than one photo via its share extension. It also has no REST API for posting directly from third-party apps.</p><p>Rather than confuse the user with a broken workflow that deceptively looks obvious, I opted to simply save the photos to the camera roll. If you switch over to Instagram to post, they appear in the correct order (which is reversed from their spatial order in the original panorama) to make selection as simple as possible. Watch the demo movie above to see this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*z8-MDLlynynBOIvEYjbFYg.jpeg" /><figcaption>Message alert after saving</figcaption></figure><h4>Debugging Swift</h4><p>Basic features like inspecting variables in structs and objects simply don’t work most of the time. Hopefully this improves now that there’s finally an ABI, but man, that’s painful.</p><h4>Xcode’s git integration</h4><p>My use of git is trivial. One user using the local repo created for me by Xcode when I created the project. None of the git features in Xcode worked for me, and they often interfered with other trivial tasks such as renaming files.</p><ul><li>Renaming files in the project navigator failed on multiple occasions.</li><li>Git status indicators were incorrect. Using the Refresh command did not help.</li><li>There were error messages about failing to communicate with a background process that were probably related. Quitting and restarting Xcode did not help.</li></ul><p>For every git task I resorted to using the command line, or something that actually works with git, such as my old friend <a href="https://www.barebones.com/">BBEdit</a> or <a href="https://code.visualstudio.com/">Visual Studio Code</a>. I then had to manually repair issues due to renamed files in Xcode afterwards. It was the opposite of helpful. I had used Xcode’s git integration in the past successfully, so this was disappointing.</p><h4>AppStore review</h4><p>This was the most frustrating issue I encountered. I tested my app on multiple devices. I had friends try it through Test Flight. None of them encountered serious issues. My app was repeatedly rejected. The reviewer said that the app did not show any Panoramas. After going back and forth and making changes to ensure that my app would find and download images in iCloud and the Photostream, I got the same rejections.</p><p>When I finally asked for them to demonstrate to me that they actually had panoramas in their photo library, my app was approved! So perhaps there was some kind of misunderstanding about what the app was for, or it suddenly worked for them after I asked for this information, but it was more than a week of frustration and low-quality communication. I still don’t know if there is a real, fundamental problem that only the AppStore reviewer saw.</p><p>When an app is rejected, you have no idea what they tried. They don’t tell you if it worked on one device, but failed on another device. I know they have to review a <a href="https://www.urbandictionary.com/define.php?term=kabillion">kabillion</a> apps, so they need to be efficient, but it’s not a great experience for the developer. It would be a big help if they provided a test plan and what they ran it on.</p><h3>Version 1.1 — Adding a Share Extension</h3><p>While I had the code for version 1.0 done in a jiffy, adding a share extension seemed like the next step. A step which proved to be much more work than the original app, and one that brought more surprises.</p><h4>The App Extension API</h4><p>Put simply, the API for application extensions is bizarre. Some of the critical classes, such as NSExtensionContext are used for multiple extension types, but some methods and properties are for use in specific types of extensions. Some classes play roles on both sides of the sharing mechanism, e.g. NSItemProvider. Some of the documentation is unclear as well, and some calls don&#39;t translate well into Swift.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*wuPwlCc27031k21Ss7uw7A.jpeg" /><figcaption>The Panotronic share extension in the share sheet in Photos</figcaption></figure><h4>Can’t I just launch my app from the extension?</h4><p>No. There are ways, but Apple doesn’t want you to. This is one of those cases where NSExtensionContext has methods that are only intended for specific extension types. In this case, there is an openURL method on NSExtensionContext that looks like it could launch my app, but it doesn&#39;t work in a share extension.</p><h4>Memory Constraints</h4><p>I wanted to have the same UI in the extension as in the application: the view with the square photos with a save button. However, share extensions have such a limited memory budget, it’s not possible to render a panoramic photo inside one at full resolution. Working around that constraint lead to a bit of complexity and a less efficient workflow.</p><h3>Rethinking the Workflow</h3><p>Given the constraints of the extension environment, I resorted to a workflow where my share extension copied the shared photo to my application group container. (That container is a folder in the sandbox the Panotronic share extension and the Panotronic app can both safely access). This moved most of my problems from the extension to the app, and it also seemed more in keeping with the intent of share extensions. The surprises kept coming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*XIRFbTFypL5GLN2aFTNKsw.jpeg" /><figcaption>The share extension view</figcaption></figure><h4>Displaying That Preview</h4><p>While the share extension API will provide a thumbnail from some files, it won’t in all cases, so I had to generate the preview myself. I’ve already mentioned that there’s not enough memory to simple create a UIImage from a panoramic photo.</p><p>I solved this by using <a href="https://developer.apple.com/documentation/imageio/1465099-cgimagesourcecreatethumbnailatin">CGImageSourceCreateThumbnailAtIndex</a> to load a thumbnail. I also had to set the kCGImageSourceCreateThumbnailFromImageAlways flag because some files (such as those from digital cameras) have stored thumbnails with letter-boxing or at low quality (they are probably optimized for the screen on the camera), so I could not rely on those.</p><p><strong>TIP</strong>: If you’re building a photo app, make sure you test it with files from devices other than the platform you are developing on.</p><h4>Temp files are really quite temporary</h4><p>If I saved a file provided by an NSItemProvider to the URL at FileManager.temporaryDirectory when my share extension view controller was loaded, that file was deleted by the time the user pressed Save. I had to use a non-temporary location for my temporary files.</p><h4>Hello UIDocument, Goodbye UIDocument</h4><p>I tried using a UIDocument subclass, but found its behavior surprising and not useful for this application. For example, when you create a UIDocument with a URL at one location, and then save the document to URL at a different location, the first file is deleted. I guess somebody thought that was a good default behavior.</p><h4>Compatibility With Other Apps</h4><p>I had things working with the stock iOS Photos app, but my UI did not appear when I tried it in other apps, like Adobe Lightroom or Google Photos.</p><p>Surprised? No.</p><p>Additionally, even in Photos, my UI did not animate on screen. I wound up creating a view controller that only exists to present the real view controller with animation. That seemed to solve both problems.</p><h3>One UICollectionView, Two UICollectionViewDataSources</h3><p>Meanwhile, back in the app, we need to detect and present those files shared from the extension. I created a composite data source that uses one data source per UICollectionView section. That dropped right into my UICollectionViewController. One data source would be the a modified data source that used the <a href="https://developer.apple.com/documentation/photokit">PhotoKit</a> API&#39;s, and a new data source to load files from the folder that the share extension copies photos to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*Lvr4kqLrTEbWSsd7fRvFBw.png" /><figcaption>A section for photos shared by the extension, at top.</figcaption></figure><h4>Trash</h4><p>I still wrestle with my decision to not automatically delete the images in the Shared to Panotronic section of the collection after the user saves the square photos. That seemed like it would be confusing. I added a trash icon in the collection view that deletes all of the items in the Shared to Panotronic section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*qApELr4pdVbP2GmabwgC2g.jpeg" /><figcaption>Cleaning up those shared images</figcaption></figure><h3>In Conclusion</h3><p>Developing software is still a maze of fragile tools, technology churn, and frustrating surprises. I think I’ll extend my time away from full-time software development a little longer, but I’ll continue to tinker with code, perhaps putting out more small projects like Panotronic.</p><p>If you made it to the end of this post, I appreciate your time. You can reach me here or on <a href="https://twitter.com/recordtronic">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7309db2bdefb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[That thing I really needed to know about KVO that they didn’t tell me]]></title>
            <link>https://medium.com/@jongary/that-thing-i-really-needed-to-know-about-kvo-that-they-didnt-tell-me-545bcdd69055?source=rss-c5073b85b624------2</link>
            <guid isPermaLink="false">https://medium.com/p/545bcdd69055</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Jon Gary]]></dc:creator>
            <pubDate>Thu, 01 Mar 2018 23:22:50 GMT</pubDate>
            <atom:updated>2018-03-02T03:06:38.155Z</atom:updated>
            <content:encoded><![CDATA[<h3>Jon Gary ‎יוֹנָתָן on Twitter</h3><p>That moment when you discover NSKeyValueChangeDictionary&#39;s isRetainingObjects ivar and suddenly a mysterious crash makes sense.</p><p>When the <a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#//apple_ref/doc/uid/10000177-BCICJDHA">Key Value Observing</a> machinery calls your observeValueForKeyPath:ofObject:change:context: method, the dictionary passed in the change parameter is not a garden-variety NSDictionary. It’s a special subclass of a dictionary called <a href="https://github.com/apportable/Foundation/blob/master/System/Foundation/src/NSKeyValueChangeDictionary.h">NSKeyValueChangeDictionary</a>. This dictionary may have unsafe, unretained references to the objects it contains, so if you store it anywhere that outlasts the invocation of your observeValueForKeyPath:ofObject:change:context: method, it may be full of dangling references, spiders, and/or ghosts (I’m sure this is a great optimization as it avoids a lot of retain/release activity during changes).</p><p>If you want to process changes asynchronously, make a copy. Not with the copy method, but with -[NSDictionary dictionaryWithDictionary:] to ensure you get a fresh, normal NSDictionary.</p><pre><br>- (void)observeValueForKeyPath:(NSString *)keyPath</pre><pre>ofObject:(id)object</pre><pre>change:(NSDictionary *)change</pre><pre>context:(void *)context {<br>    //... check keyPath, context, etc, per usual</pre><pre>    NSDictionary *safeChange = [NSDictionary dictionaryWithDictionary:change];</pre><pre>    // Hypothetical method to process the change asynchronously<br>    [self asyncProcessKVOChange:safeChange];</pre><pre>}<br></pre><p>I hope that’s helpful.</p><p>P.S. Don’t use KVO if you don’t have to.</p><p>P.P.S. Sometimes you have to.</p><p>P.P.P.S. If you spot the place where this is documented feel free to point it out with a link.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=545bcdd69055" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>