<?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/"
	>

<channel>
	<title>#iOS 10 Archives - anteelo</title>
	<atom:link href="https://anteelo.com/tag/ios-10/feed/" rel="self" type="application/rss+xml" />
	<link>https://anteelo.com/tag/ios-10/</link>
	<description>Leading Digital Solution Firm</description>
	<lastBuildDate>Fri, 18 Jun 2021 06:52:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://anteelo.com/wp-content/uploads/2020/01/cantlogo.png</url>
	<title>#iOS 10 Archives - anteelo</title>
	<link>https://anteelo.com/tag/ios-10/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Creating Widgets in iOS 10</title>
		<link>https://anteelo.com/creating-widgets-in-ios-10/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-widgets-in-ios-10</link>
		
		<dc:creator><![CDATA[Anteelo Master]]></dc:creator>
		<pubDate>Wed, 01 Jan 2020 06:47:45 +0000</pubDate>
				<category><![CDATA[App Development]]></category>
		<category><![CDATA[#app]]></category>
		<category><![CDATA[#Application]]></category>
		<category><![CDATA[#iOS]]></category>
		<category><![CDATA[#iOS 10]]></category>
		<category><![CDATA[#iPhone]]></category>
		<category><![CDATA[#UI]]></category>
		<category><![CDATA[#Widgets]]></category>
		<guid isPermaLink="false">https://anteelo.com/?p=3522</guid>

					<description><![CDATA[<p>Widgets are something that every trending iOS application is looking forward to. Widgets help users to get some quick and relevant information without even opening the app. They are best suited for applications like Weather apps, To-Do list apps, Calendar apps which might show a day’s schedule. The widget should provide the immediate and relevant information [&#8230;]</p>
<p>The post <a href="https://anteelo.com/creating-widgets-in-ios-10/">Creating Widgets in iOS 10</a> appeared first on <a href="https://anteelo.com">anteelo</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div align="justify">Widgets are something that every trending iOS application is looking forward to. Widgets help users to get some quick and relevant information without even opening the app. They are best suited for applications like Weather apps, To-Do list apps, Calendar apps which might show a day’s schedule. The widget should provide the immediate and relevant information that user must be interested in. The amount and type of information that widget carries, varies according to the requirement of the containing App of the widget.We will learn through this blog what are widgets and how to make widgets for our iOS app. We have already made an <a href="https://www.instagram.com/anteelodesign/">application</a> called RemindME which is a small To-Do list application.<img decoding="async" class="aligncenter" src="https://lh3.googleusercontent.com/proxy/fmomFEcvwIx0eNuktn9pNIus6Rb1GE9DwhwKO9IwWlNpdZLVRi9GIienXYVIBqMTYvHBcegUhkhh8x1Vomy_ekpFNo1VdTkOyiHgk25x7G60p4lOK_n--xNDraQVWJ5zwfTCGu1vghVfEeQmZBaW" alt="How to create widgets in iOS 10 | Humble Bits" /></p>
<h3>What we are going to cover<strong> </strong></h3>
<ul>
<li>iOS 10 Widget UI</li>
<li>Sharing UserDefaults and Files with Widget</li>
<li>Updating the content</li>
<li>Adjusting Widget’s Height</li>
<li>How to open App from Widget</li>
<li>When my Widget should Appear?</li>
<li>Home Screen Widget</li>
</ul>
<h3>Start-Up Project</h3>
<p>We have already created an application that allows user to add some To-Do items with title and description and shows its status as done or not done. This will be containing app for our widget.</p>
<h3>Getting Started</h3>
<p>So, enough saying now and let’s get started with the real code. Widgets are nothing but a type of App extensions called <em>Today Extension</em>. So if anybody needs to know about app extensions, you can see this apple documentation. Now, add target by selecting <strong>File/New/Target</strong> and then under <strong>iOS</strong> section select <strong>Today</strong> <strong>extension</strong> and press <strong>next</strong>. After that give name to your widget and select the containing app as your project.</p>
<p>Now we can see in project navigator a new group will be added with our Widget’s name. Change Schema and select target as the widget and run project. You will  see widget in the <a href="https://anteelo.com/">notification center</a> of our simulator with a message “Hello world” like this.</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter" src="https://miro.medium.com/max/12750/1*kH4aYZS2ZCezt9uO5FOCjA.png" alt="10 Tips on Developing iOS 14 Widgets Swift and SwiftUI | The Startup" width="643" height="340" /></p>
<h3>iOS 10 Widget UI</h3>
<p>Let us now design how our widget is going to look like. Open the storyboard of our newly added target and remove the default label. We are going to add a <em>tableview</em> and a button and two labels in our <em>tableview</em> cell. We have added UIImage for the status of the reminder and labels for title and description of the reminder. We have added a class called <strong>WidgetTableViewCell. </strong>Select the tableview cell and in identity inspector, add class name as <strong>WidgetTableViewCell. </strong>Add constraints to the views as needed and connects the outlets in the <strong>WidgetTableViewCell </strong>using <strong>Assistant</strong> <strong>Editor</strong>.</p>
<p><img decoding="async" class="aligncenter" src="https://images.applypixels.com/images/originals/e5cfdff7-e1d0-42e3-8ebe-ca8de1800794.png" alt="iOS 10 UI" width="405" height="405" /></p>
<p>We will also add <strong>Visual Effect View With Blur</strong>  from the object browser in our tableview cell. This is to add vibrancy effect to our widget. This causes a blur background in our Widget’s view. This is to make it look similar to what default iOS widgets look like. Make an outlet of visual effect view in the <strong>WidgetTableViewCell</strong> and name it as “visualEffectView”.</p>
<p>This ensures that vibrancy is similar to system-defined one for Today Extensions and the UI looks like default iOS 10 widgets.</p>
<h3>Sharing UserDefaults and Files with Widget</h3>
<p>Widgets are nothing but extensions. Extensions are just like another application so our containing app and widgets cannot communicate directly. There may be situations when our containing app and widget need to share some data. We can do that by sharing UserDefaults between them.</p>
<p>To enable this, select the main App target and choose Capabilities tab and then enable App groups. We require apple developer account for this. Now, create an app group. App group name must start from “group”. We have created an app group with name “group.com.quovantis.RemindMe”</p>
<p>Similarly we will repeat the process by selecting the target for widget. But we don’t have to create a new app group, we can use the one we created before. Now when we will save or retrieve anything from UserDefaults we will use this group.</p>
<p>We have made a class that will manage writing and reading our Reminders from UserDefaults. This code can be used by both our containing app as well as our widget extension.</p>
<p>We have used <strong>UserDefaults(suiteName: “group.com.quovantis.RemindMe”)</strong> for writing and reading our Reminders. This ensures both our containing app and the Widget extension save and read the data from a shared UserDefault under a common suite.</p>
<p>Now if we have to use the same <strong>UserDefaultsManager</strong> class in our Widget target also, we will have to enable it explicitly from the <strong>File inspector</strong>. Select the file <strong>UserDefaultsManager.swift</strong> and from <strong>File</strong> <strong>inspector</strong> check <strong>RemindMeWidget</strong>. Similarly if we have to import any other file like <strong>Assets.xcassests</strong> into our widget extension we can do the same.</p>
<p>Now we have shared <strong>UserDefaults</strong> between main app and widget, we can now add content to our widget. We will read data from the <strong>UserDefaults</strong> and will show the reminders in the table view of the widget. Widget will show the title and description of the Reminder and a button checked or unchecked depending upon the status. We will fetch the reminders from the UserDefaults in the <strong>viewWillAppear</strong> and will refresh the tableView. You can look the code in the <strong>TodayViewController.swift</strong> file in the <strong>RemindMeWidget</strong> folder.</p>
<p>We can also add actions to our widget. We have added an action to the button in our widget. When it is pressed that reminder is marked as done by updating status of the reminder in UserDefaults. Code for this action is written in <strong>WidgetTableViewCell </strong>class.</p>
<p>Now when we add any reminder from our main App, it will be reflected back to our widget also.</p>
<h3>Updating the content</h3>
<p>Now we will see how to add support to our widget to update its view when it’s off-screen, by allowing the system to create a snapshot. The system periodically takes snapshot to help our widget stay up to date. That is done through <strong>widgetPerformUpdate</strong> method.</p>
<p>We need to replace the existing implementation of <strong>widgetPerformUpdate</strong></p>
<p>If we get reminders from the <strong>UserDefaults</strong> successfully, we update the interface and the function calls the system-provided completion block with the <strong><code class=" prettyprinted"><span class="pun">.</span><span class="pln">newData</span></code></strong> enumeration. This informs the system to take the fresh snapshot and replace it with the current.</p>
<p>If we fail to get reminders then we call the completion handler with <strong>.failed</strong> enumeration. This informs the system that no new data is available and the existing snapshot should be used.</p>
<h3>Adjusting Widget’s Height</h3>
<p>As we have limited space in our Today View, System provides a fixed height to all the widgets. We have to design our widget UI in accordance with that . But we can also provide the option to increase the height of the widget so as to show more information in the Today view.</p>
<p>Our <strong>TodayViewController</strong> conforms to the <strong>NCWidgetProviding</strong> that provides the method to do this. There are two modes of the Widget of type <span class="s1"><strong>NCWidgetDisplayMode</strong>, c</span>ompact and expanded.</p>
<p>This will specify that widget can be expanded and we get a default button to expand and close the widget. Now add this method to adjust the size of the widget.</p>
<p>Whenever the widget height is adjusted this method is called where we have specified the height in case of compact and expanded state. In expanded mode we set <strong>preferredContentSize</strong> to the combined height of the cells of our tableview in Widget and when it is in compact mode we set <strong>preferredContentSize</strong> as CGSize() which gives the default height to the widget.</p>
<h3>How to open App from Widget</h3>
<p>Users may also want to open the containing app from widgets so as to have a detailed look over the information shown in the widget. For that we will have to allow our widget to open our containing app.</p>
<p>For this we use URL Schemes. We can open any app that supports URL Scheme from our widget but we should do that rarely. As user may get confused regarding the container app of the widget. Generally we should link the containing app of the widget only.</p>
<p>For enabling the URL Schemes in our containing app we need to add the following rows in our info.plist</p>
<p>After that we use the <strong>extensionContext</strong> property of type <strong>NSExtensionContext</strong> in our <strong>TodayViewController</strong> class to call the openUrl function. We have written this code in <strong>didSelectRowAt Index</strong> of our tableView</p>
<div>
<h3>When my Widget should Appear?</h3>
<p>There can be situations when under certain circumstances, you want your widget to appear in Today view. For example, there is no new or noteworthy information to show and you want to hide your widget until something new information comes up.</p>
<p>You can do this by using <strong>setHasContent: forWidgetWithBundleIdentifier:</strong> method of class <strong>NCWidgetController</strong>. Set the flag as true or false to show or hide the widget respectively and specify the bundle identifier of the particular widget which we want to hide or show.</p>
<p>In our case we will hide the widget if there are no reminders in our app. And as soon as the count of the reminders is one or more we will show the widget again.</p>
<p>We can write the code to hide widget from the TodayViewController itself but we must always avoid this. Our containing app should be the one which will decide when to hide or show the widget.</p>
<p>Write this function in the <strong>ReminderListViewController-</strong></p>
<h3>Home Screen Widget</h3>
<p>We have seen applications show widget along with the quick actions when we <em>Force Touch</em> the app icon. If we have only one widget in our app, it is shown by default. But if our app offers two or more widgets then we will have to specify the bundle identifier of the widget in the <strong>info.plist</strong> that we want to show when we <em>Force touch</em> our app.</p>
<p>Add <strong>UIApplicationShortcutWidget</strong> key in the <strong>info.plist</strong> with the bundle identifier of the widget as its value.</p>
<h3>Summary</h3>
<p>So, this is all about <a href="https://anteelo.com/ios-developer/">iOS</a> 10 Widgets for <a href="https://anteelo.com/advantages-of-developing-an-iphone-app-for-your-company/">iPhone</a>. Thank you for reading this tutorial and I hope you enjoyed this. You can think some more innovative ideas to explore more possibilities from Today extensions and think about ways to update your existing applications with your own widgets.</p>
</div>
</div>
<p>The post <a href="https://anteelo.com/creating-widgets-in-ios-10/">Creating Widgets in iOS 10</a> appeared first on <a href="https://anteelo.com">anteelo</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
