Skip to content

Instantly share code, notes, and snippets.

@markvanwijnen
markvanwijnen / index.html
Last active August 24, 2021 21:39
Service Worker Update Available Banner Sample with ServiceWorkerUpdateListener
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Web Application</title>
</head>
<body>
<div id="update-banner" data-state="noupdate">
var CACHE_NAME = 'my-web-app-version-v3';
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
return cache.addAll([
'./',
'./index.php',
'./ServiceWorkerUpdateListener.min.js'
@markvanwijnen
markvanwijnen / index.html
Last active August 24, 2021 20:36
Service Worker Update Available Banner Sample
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Web Application</title>
</head>
<body>
<div id="update-banner" data-state="noupdate">
var CACHE_NAME = 'my-web-app-version-v1';
// 1 - Install
// Here we wait for an InstallEvent to fire, then tell the cache which URLs it should retrieve and cache
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
return cache.addAll([
'./',
import SwiftUI
import Combine
import CommonCrypto
class TwitterAPI: NSObject, ObservableObject {
@Published var authorizationSheetIsPresented = false
@Published var authorizationURL: URL?
@Published var user: User?
private var tokenCredentials: TokenCredentials?
import SwiftUI
import SafariServices
struct SafariView: UIViewControllerRepresentable {
class SafariViewControllerWrapper: UIViewController {
private var safariViewController: SFSafariViewController?
var url: URL? {
didSet {
if let safariViewController = safariViewController {
import SwiftUI
import Combine
struct ContentView: View {
@EnvironmentObject var twitterAPI: TwitterAPI
var body: some View {
VStack {
if let screenName = twitterAPI.user?.screenName {
Text("Welcome").font(.largeTitle)
import SwiftUI
@main
struct TwitterTutorialApp: App {
@StateObject var twitterAPI = TwitterAPI()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(twitterAPI)
self.subscriptions["oAuthAccessTokenSubscriber"] =
self.oAuthAccessTokenPublisher(temporaryCredentials: temporaryCredentials,
verifier: oAuthVerifier) // 1
.receive(on: DispatchQueue.main) // 2
.sink(receiveCompletion: { _ in // 3
// Error handler
}, receiveValue: { [weak self] (tokenCredentials, user) in // 4
guard let self = self else { return }
// 5
private var tokenCredentials: TokenCredentials?