일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Tags
- iOS 광고달기
- reactorkit
- 하단 네비게이션바
- codebase
- snapkit
- failed: No such file or directory (2)
- RxCocoa
- archive error
- 테이블뷰 셀 밀어서 삭제
- navigationbar
- 화면 가리기
- MVVM
- AppleLogin
- color 변경
- RxSwift
- 소셜로그인
- print vs dump
- then
- testflight error
- 테이블뷰 밀어서 삭제
- CryptoSwift
- Business Manager
- 로그출력
- 스토리보드 없이
- 아카이브 에러
- 테이블 뷰
- 비공개 앱 배포
- 로그 찍기
- Apple Enterprise
- 백그라운드 진입시 화면
Archives
- Today
- Total
ukSeung iOS
[Swift] Hotspot Configuration, 핫스팟 연결 본문
안녕하세요 욱승임다ㅎ
이번 포스팅에서는 기기간 핫스팟 연결을 구현 해보겠읍니당
Capability
작동 방식
소스코드
View
//
// HotspotConfigurationViewController.swift
// SwiftPractice
//
// Created by ukseung.dev on 2023/05/22.
//
import Foundation
import UIKit
import RxSwift
final class HotspotConfigurationViewController: UIViewController, UIViewControllerAttribute {
let viewModel = HotspotConfigurationViewModel()
let disposeBag = DisposeBag()
var navTitle: String?
lazy var button = UIButton(type: .system).then {
$0.setTitle("connectToHotspot", for: .normal)
}
// getWiFiInformation 로그인 성공 후 UILabel.text
lazy var wifiInfoLabel = UILabel().then {
$0.numberOfLines = 0 // 여러 줄
$0.sizeToFit()
}
override func viewDidLoad() {
super.viewDidLoad()
setNavigationBar()
setUI()
setAttributes()
bindRx() // 미사용 함수
}
func setNavigationBar() {
self.navigationItem.title = navTitle ?? ""
}
func setUI() {
self.view.backgroundColor = .white
self.view.addSubview(button)
self.view.addSubview(wifiInfoLabel)
}
func setAttributes() {
button.snp.makeConstraints {
$0.top.equalTo(self.view.safeAreaLayoutGuide).offset(30)
$0.left.equalTo(30)
$0.right.equalTo(-30)
$0.height.equalTo(50)
}
wifiInfoLabel.snp.makeConstraints {
$0.left.equalTo(20)
$0.right.equalTo(-20)
$0.top.equalTo(button.snp.bottom).offset(40)
$0.height.equalTo(50)
}
}
func bindRx() {
button.rx.tap
.subscribe(onNext: viewModel.connectToHotspot)
.disposed(by: disposeBag)
viewModel.inCompleted
.bind(to: wifiInfoLabel.rx.text)
.disposed(by: disposeBag)
}
}
ViewModel
//
// HotspotConfigurationViewModel.swift
// SwiftPractice
//
// Created by ukseung.dev on 2023/05/22.
//
import Foundation
import NetworkExtension // 핫스팟 import
import RxSwift
import RxCocoa
final class HotspotConfigurationViewModel {
let inCompleted = PublishRelay<String>()
func connectToHotspot() {
let hotspotConfig = NEHotspotConfiguration(ssid: "욱", passphrase: "1234567890", isWEP: false) // 내 기기 핫스팟 하드코딩
hotspotConfig.joinOnce = true
NEHotspotConfigurationManager.shared.apply(hotspotConfig) { error in
if let error = error {
print("핫스팟 연결 실패")
self.inCompleted.accept("Failed to connect to Wi-Fi hotspot: \(error.localizedDescription)")
} else {
print("핫스팟 연결 성공")
self.inCompleted.accept("Successfully connected to Wi-Fi hotspot")
}
}
}
}
ps. 핫스팟이 미리 켜져있어야함 !
GitHub
GitHub - shinseunguk/SwiftPractice: SwtiftPractice
SwtiftPractice. Contribute to shinseunguk/SwiftPractice development by creating an account on GitHub.
github.com
728x90
반응형
'iOS > Swift' 카테고리의 다른 글
[Swift] 시뮬레이터 디바이스 모델명 가져오기 / Get Simulator IPhone Model Name (0) | 2023.08.25 |
---|---|
[Swift] 화면이동시 SafeArea Background Color이 변경 되는 이슈 (2) | 2023.06.20 |
[Swift] RxSwift+MVVM, Sign In with Apple 애플 로그인 (0) | 2023.05.23 |
[Swift] UITableView Cell 밀어서 삭제 (0) | 2023.05.21 |
[Swift] ScrollView 스크롤 네비게이션바 hide On/Off (1) | 2023.05.19 |