---
title: "#296: Today Extension B-Sides 📼"
url: https://littlebitesofcocoa.com/296-today-extension-b-sides
author: Jake Marsh
date: 2017-02-13
published: 2017-02-13
topics: ["UIKit","Extensions"]
description: "We first covered Today Extensions way back in Bite #36. They're a great way to offer quick, glanceable information or entry-points to our app."
---

# #296: Today Extension B-Sides 📼

By Jake Marsh, February 13, 2017. HTML: https://littlebitesofcocoa.com/296-today-extension-b-sides

We first covered _Today Extensions_ way back in [Bite #36](https://littlebitesofcocoa.com/36). They're a great way to offer quick, glanceable information or entry-points to our app. Today we'll take a look at some lesser known features of _Today Extensions_, and how we can use them in our code. Let's begin.

## 3D Touch Shortcut Widgets

First up, is one of the newest additions to the _Today Extension_ world: <i>3D Touch Homescreen Widgets</i>.

The coolest bit is, we don't really need to do anything to "get" this. If our app has a _Today Extension_, the widget will automatically appear when a user **3D Touches** our app's **icon**.

The [B-Side](https://www.littlebitesofcocoa.com/topics/80-b-sides?v=l) comes into play when we have <i>multiple</i> _Today Extensions_ in our app. We'll need a way to tell the system which one to display above our **icon**. We can do this by adding a new key to our app's `Info.plist`:

```
UIApplicationShortcutWidget
```

(We can also choose <i>"Home Screen Widget"</i> from the keys dropdown).

<img src="https://media.littlebitesofcocoa.com/296-1.png" />

Neat!

## Conditional Display

_Today Extensions Widgets_ don't have to **always** be visible in the <i>Today</i> view. We can actually tell the system whether or not our _widget_ should be displayed with this one **function**:

``` swift
NCWidgetController
  .widgetController()
  .setHasContent(true, 
    forWidgetWithBundleIdentifier: "com.littlebitesofcocoa.latest")
```

<p class='break'></p>

Calling this with `false` will hide the _widget_ in the <i>Today View</i> until our app calls the **function** again with a `true` value.

## Opening Our App

This one is a <i>bit</i> of a stretch to truly call a [B-side](https://en.wikipedia.org/wiki/A-side_and_B-side), but it can easily be done incorrectly, so here we are.

It's quite common for a _Today Extension Widget_ to need to open its containing app.

Apple has tightened the reigns in recent OS releases to "validate" when and how apps (and specifically _Today Extensions_) can open apps. Not to worry, we can use this special **function** on an `NSExtensionContext` to open a [deep link](https://littlebitesofcocoa.com/62-jlroutes) into our app.

``` swift
self.extensionContext?.openURL(NSURL("lboc://bites/296"), completionHandler: nil)
```

**Pro Tip:** Opening our own app (i.e. our app that contains the _Today Extension_) is just fine, but beware if we start trying to open other apps using this **function**, Apple may scrutinize our _Today Extension_ further during **App Review**.

<p></p>
