قالب وردپرس درنا توس
Home / IOS Development / # 296: Today Extension B-Sides 📼 – Little Bites of Cocoa

# 296: Today Extension B-Sides 📼 – Little Bites of Cocoa



Topics

Topics

We Covered First Today Extensions Way Back in Bite # 36. They are a great way to provide quick, clear information or entry points to our app. Today, we take a look at some lesser known features of Today Extensions and how we can use them in our code. Let us begin.

3D Touch Shortcut Widgets

First up is one of the latest additions to Today Extension World: 3D Touch Homescreen Widgets .

The coolest thing is, we really do not need to do anything to "get" this. If our app has a Today Enhancement the widget automatically appears when a 3D Touches ] ] icon is used.

The B page comes into play when we have more Today Extensions in our app. We need a way to tell the system to be shown over the icon . We can do this by adding a new key to the app's Info.plist :

  UIApplicationShortcutWidget

(We can also select "Home Screen Widget" from the Keys dropdown menu.

Neat!

Conditonal Display

Today Extensions Widgets does not have to always be visible in Today . We can actually tell the system if our widget is displayed with this feature :

  NCWidgetController 
  .   widgetController   () 
  ]   setHasContent   (  true  
      for WidgetWithBundleIdentifier :    "com.littlebitesofcocoa .latest ") 

Calling this with false will hide the widget in Today View to our app calling the feature again with a value true .

Opening our app

This is a piece of a stretch to really call a B-side, but it can easily be done wrong, so here we are.

It's quite common for an Apple Extension Widget to open the containing app.

Apple has tightened governments in recent OS releases to "validate" when and how programs (and specifications ifically Today Extensions ) can open apps. Do not worry, we can use this special feature on a NSExtensionContext to open a deep link in our app.

  by yourself .   extensionContext ?    openURL   (  NSURL   (  "lboc: // biter / 296". ),    completionHandler :    nil [19659018]) 

Pro Tip: To open our own app (ie our app containing Today Extension ) is just fine, but be careful if we start trying to open other apps Using this Apple may review our Today Extension further under App Review .


Source link