Skip to content

Instantly share code, notes, and snippets.

View donnywals's full-sized avatar
:bowtie:

Donny Wals donnywals

:bowtie:
View GitHub Profile

Core Location

  • When an app needs always authorization, they will not receive this authorization immediately
  • Apps that request always authorization receive provisional access, meaning that the user allows when in use access but the app thinks it has always access.
  • An app can then begin doing what they must do in the background and when the time is right, iOS will prompt the user for always access and the app will then receive the "real" status (when in use / always).
  • This prompt does not appear immediately and the background event that triggered the location prompt is stored for a limited time.
  • If a user allows access, your app receives the location. This will not be realtime due to the prompt not being shown immediately. Events that are too old are dropped. Plan for this.
  • If you request when in use location, you don't receive the provisional always authorization.
  • in iOS 13 you can now always use all the different location apis, like for instance region monitoring, visit tracking etc. This me

Introducing Swift UI

Building your First App

To use previews you need macOS Catalina

  • Canvas shows previews by compiling and running code. You can do a lot of customizing to these previews.
  • You can drag UI elements into the preview and Xcode updates the code accordingly.
  • VStack and HStack are containers that act like a UIStackView.
  • You can edit the UI code and in the Preview. Both update each other accordingly.
  • You can use the preview editor to see and modify certain properties, like for instance alignment or text sizes.

CloudKit and Core Data

  • Core Data and CloudKit are conceptually similar but implemented in very different ways.
  • You can now check a use CloudKit checkbox when you add Core Data to your app.
  • You need to add the iCloud and Background mode capabilities yourself in order to use CloudKit and update your app in the background.
  • Xcode creates a container identifier for your app.
  • NSPersistentCloudKitContainer managed persistent stores that sync data too iCloud. The CloudKit container is a subclass of the NSPersistentContainer.
  • The CloudKit container contains all the boilerplate code that you would normally have to write yourself.
  • Apple asks for feedback on this container explicitly.
  • CloudKit container creates a local replica of the CloudKit store.

Build log:

/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace /Users/donnywals/Projects/apple-spike-core-data-helpers/PersistentStore.xcodeproj/project.xcworkspace -scheme PersistentStore -configuration Debug -IDECustomDerivedDataLocation=/Users/donnywals/Library/Developer/Xcode/DerivedData SYMROOT=/Users/donnywals/Library/Developer/Xcode/DerivedData/PersistentStore-eveisykprmnxhkbpwnknbrjujruv/Build/Products OBJROOT=/Users/donnywals/Library/Developer/Xcode/DerivedData/PersistentStore-eveisykprmnxhkbpwnknbrjujruv/Build/Intermediates.noindex -destination arch=x86_64 -destination-timeout 15 TEST_AFTER_BUILD=NO build
User defaults from command line:
    IDECustomDerivedDataLocation = /Users/donnywals/Library/Developer/Xcode/DerivedData

Build settings from command line:
    OBJROOT = /Users/donnywals/Library/Developer/Xcode/DerivedData/PersistentStore-eveisykprmnxhkbpwnknbrjujruv/Build/Intermediates.noindex
    SYMROOT = /Users/donnywals/Library/Developer/Xcode/DerivedData/PersistentSt

What’s New in Core ML, Part 1

If you want to know about tools, check out part 2 of this talk.

Model size

Running a model on a device has some advantages:

  • Privacy, data remains on the device
  • Speed, the model is used in real time
  • No extra servers needed
  • No internet needed, it’s always available

What’s New in Testing

Code coverage

In Xcode 9.3 code coverage gained improved reporting and performance. The time to load code coverage has been greatly reduced. Accuracy has also been improved. Especially header files were not analysed properly in Xcode 9. This has been fixed in 9.3.

You can now enable or disable code coverage on a per-target basis. This is nice because throw party code will then no longer pollute your coverage results. You can exclude targets in your build scheme editor for your test target.

Test selection

  • You want to have different test for different builds.
  • You can tell a scheme to not run certain tests.

Best Practices and What’s New with In-App Purchases

Introductory prices

SKProduct.introductoryPrice is an instance of SKProductDiscount. Just like a normal SKProduct, SKProductDiscount has a price and priceLocale. It also has a subscriptionPeriod. This period has a unit in the form of a month, week, month, year and a number of units. For instance 3 month units is possible. There is also a numberOfPeriods. Another property on SKProductDiscount is paymentMode.

If you have a 3 month cycle for your subscriptions, you can offer 6 months of access for a discount by setting numberOfPeriods to 2. If you set paymentMode to payAsYouGo, the user pays the second period after the first ends. You could also do a payUpFront setting so the user will pay the first two periods all at once. After the 6 month trial is up, the next renewal is for three months.

The last paymentMode is freeTrial, this gives the entire introductory period to the user for free.

Since iOS 11.2, subscriptionPeriod

Integrating Apps and Content with AR Quick Look

AR Quick look allows people to quickly place 3d models in the real world to see what they look like. Developers / designers provide a 3D model and AR Quick look does the rest. This uses quick look technologies throughout the system. On non-ARKit compatible devices the user can only explore the model, without seeing it in the real world. AR models can contain animations. Transform and skeletal animations are supported.

AR Quick look also works with accessibility and voice over. User get queues when items go off screen or when they come back on screen.

Files, mail messages, notes, news and safari have adopted AR Quick look. People can now use a special html tag to add 3d models to websites.

USDZ is a new file format for distributing 3D models in iOS. A model and textures are bundled in a single file. It’s based on Pixar’s USD format. This file format is supported on iOS and macOS and a converted is available.

Getting the most out of playgrounds in Xcode

Fundamentals (“old” stuff)

  • You can show results of lines of code inline with your code by clicking the square next to the result in the result sidebar
  • You can use UIView and even UIViewController to give a live preview.
  • Show a live preview with the following snippet:
import PlaygroundSupport

let vc = //

What’s new in User Notifications

Grouping

  • Grouping is performed by default.
  • You can use threads by adding the thread-id or threadIdentifier for your notification.
  • The thread id is already used for content extension forwarding. It now does grouping on notifications as well.
  • Notifications without thread id are bundled with the notification group for your app.
  • If you add a thread id, a new group is made for every thread id.
  • Users can tweak grouping. Automatic groups by app / thread. By app groups by app, ignoring threads. Or the user can turn off grouping to keep old style notifications.
  • The latest notification is shown on the top of a group