Home News Twitter Developer builds an iOS widget for K-pop stars for fans to...

Twitter Developer builds an iOS widget for K-pop stars for fans to stan

KpopTwitter is one of the most popular hashtags available on Twitter recording a whopping 6.1 billion Tweets in 2019 alone. Apparently, the engagement with these tweets rose 15 percent last year with K-Pop bands like BTS and EXO taking the front seat with the most tweets. For any K-Pop fan, knowing what their favorite band or band member does or doesn’t is crucial but that only means countless taps and swipes on the internet. The widget offers a cool way of knowing stuff at a glance.

iOS 14 is the latest operating system from Apple and it is certainly one of the most powerful as well. It has a plethora of features and widgets are one of them. Widgets are tiny floating icons with variable sizes that allow users to preview stuff on their favorite apps without opening them. Widgets update on a daily basis which means users can simply unlock their iPhones and have a glance at any updates right away.

A researcher on Twitter paid homage to the #KpopTwitter hashtag creating a great widget for iOS devices. This widget grants users access to updates related to the K-Pop world with tonnes of photos rolling every day.

Building a Twitter Widget for K-Pop

Daniele, the researcher at Twitter Developer Blog posted how he built a widget allowing K-Pop fans to stay connected.

The widget updates itself every day with images sourced from Twitter. The widget users “Tweet annotations” by deciphering the context of any tweet and uses the images attached with it to showcase. The Twitter API v2 users with machine learning models for tweet annotations. It uses endpoints like a filtered stream or recent search to get the best results that you want.

The researcher used 55.888105153038958593 (Music Genre – K-Pop) as annotation for the search query. Here, the widget extension states how often the content on the widget should be refreshed. Further, the OS takes the screen time, parent app status, and other parameters in mind to update content accordingly. Here’s the code for the widget that updates every hour.

Twitter Widget Code 2
Image Courtesy: Twitter Blog

Using the results obtained from the code above, a Timeline object consisting of 24 tweets collected every hour is grouped. Deciphering the code above, the widget will update entries every hour.

Twitter Widget Code 3
Image Courtesy: Twitter Blog

There’s no shortage of tweets on Twitter and thus, there’s no endpoint. However, the “.atEnd” object ensures that the OS creates a 24 tweets Timeline to start afresh. The WidgetKit ensures that the tweets shown are arranged as per the time and date of posting it.

The researcher uses SwiftUI to create the user interface of the widget for the home screen. Taking the image, profile picture, and name of the author, and use the following code to get the job done.

Twitter Widget Code
Image Courtesy: Twitter Blog

The finished project of the widget is already available on TwitterDev Github that you can access here.


Please enter your comment!
Please enter your name here