Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOSDC 2023 Web in tvOS and watchOS

coe
September 03, 2023

iOSDC 2023 Web in tvOS and watchOS

coe

September 03, 2023
Tweet

More Decks by coe

Other Decks in Technology

Transcript

  1. Ͳ͏΍͍ͬͯΔͷ͔ "VUIFOUJDBUJPO4FSWJDFT import SwiftUI import AuthenticationServices struct ContentView: View {

    @Environment(\.webAuthenticationSession) private var webAuthenticationSession var body: some View { Button { let url = URL(string: "https://ja.wikipedia.org/wiki/MAC")! Task { try await webAuthenticationSession.authenticate(using: url, callbackURLScheme: "",preferredBrowserSession: .ephemeral) } } label: { Text("Hello, world!") } } } 63-ࢦఆͰ֘౰ͷϖʔδΛදࣔՄೳ
  2. w 4XJGU6* w 8FC"VUIFOUJDBUJPO4FTTJPO w XBUDI04 w UW04 w 6*,JU

    w "48FC"VUIFOUJDBUJPO4FTTJPO w XBUDI04 w UW04 Ͳ͏΍͍ͬͯΔͷ͔ "VUIFOUJDBUJPO4FSWJDFT
  3. w 4XJGU6* w 8FC"VUIFOUJDBUJPO4FTTJPO w XBUDI04 w UW04 w 6*,JU

    w "48FC"VUIFOUJDBUJPO4FTTJPO w XBUDI04 w UW04 Ͳ͏΍͍ͬͯΔͷ͔ "VUIFOUJDBUJPO4FSWJDFT
  4. UW04Ͱ8FCϖʔδӾཡ 6*5FYU7JFX /4"UUSJCVUFE4USJOH w /4"UUSJCVUFE4USJOHʹ͸)5.-ΛಡΈࠐΉͨΊͷ "1*͕༻ҙ͞Ε͍ͯΔ w MPBE'SPN)5.- TUSJOHPQUJPOTDPNQMFUJPO)B OEMFS

    ͳͲ w USZBXBJU/4"UUSJCVUFE4USJOHGSPN)5.-  w JNQPSU8FC,JU͕ඞཁ w /4"UUSJCVUFE4USJOH EBUBPQUJPOT EPDVNFOU"UUSJCVUFT
  5. UW04Ͱ8FCϖʔδӾཡ 6*5FYU7JFX /4"UUSJCVUFE4USJOH override func loadView() { let textView =

    UITextView() textView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouch.TouchType.indirect.rawValue)] textView.isUserInteractionEnabled = true textView.backgroundColor = .systemCyan do { let attributedText = try NSAttributedString(data: html, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil) textView.attributedText = attributedText } catch {} view = textView } BUUSJCVUFE5FYUʹ)5.-ͷ/4"UUSJCVUFE4USJOHΛઃఆ
  6. UW04Ͱ8FCϖʔδӾཡ ࢀߟɿ)5.-Λ57.-ʹม׵͢Δ 0CKFDUJWF$ - (NSString* )getTvml: (NSString* )html { const

    char* buffer = [html UTF8String]; htmlDocPtr doc = htmlReadMemory(buffer, (int)html.length, "", "UTF-8", 0); xmlNodePtr root = xmlDocGetRootElement(doc); NSMutableString* mutableString = [NSMutableString stringWithString:@"<document><head><style> .topLeftLogo { tv- position: top-left; color:rgb(255,255,255); tv-text-style: headline; }</style></head><divTemplate>"]; [mutableString appendFormat:@"%@</divTemplate></document>", [self parseTag:root]]; return mutableString; } - (NSString *)parseTag: (htmlNodePtr)ptr { NSMutableString* mutableString = [NSMutableString string]; for (htmlNodePtr node = ptr; node != NULL; node = node->next) { switch (node->type) { case XML_ELEMENT_NODE: if(node->children != NULL) { NSString* ret = [self parseTag:node->children]; [mutableString appendString:ret]; } break; case XML_TEXT_NODE: if (node->content != NULL) { NSString* content = [[NSString stringWithUTF8String:(char *)node->content] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; if (content.length != 0) { [mutableString appendFormat:@"<text class=\"topLeftLogo\">%@</text>", content]; } } default: break; } } return mutableString; } MJCYNM)5.-QBSTFSΛ࢖ͬͨ57.-ม׵