Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
- print("stream event \(eventCode)")
- switch eventCode {
- case .openCompleted:
- print("Stream opened")
- case .hasBytesAvailable:
- if aStream == inputStream {
- var dataBuffer = Array<UInt8>(repeating: 0, count: 1024)
- var len: Int
- while (inputStream?.hasBytesAvailable)! {
- len = (inputStream?.read(&dataBuffer, maxLength: 1024))!
- if len > 0 {
- let output = String(bytes: dataBuffer, encoding: .utf8)
- if nil != output {
- print("server said: \(output ?? "")")
- Вот тут я пытаюсь перейти на другой View меняя параметр
- TestView().load()
- }
- }
- }
- }
- ....
- }
- struct TestView: View {
- @Environment(\.presentationMode) var presentationMode
- @State private var showingAlert = false
- @State private var name = ""
- @State private var showLoading = false
- @State var whImg: CGFloat = 250
- @State var testBool = true
- let json = """
- {"command": 0, "device":"Test"}
- """
- let chatRoom = TCP_Communicator()
- var body: some View {
- VStack {
- HStack {
- Button(action: { self.presentationMode.wrappedValue.dismiss() }
- , label: {
- Image(systemName: "arrow.left")
- Text("Назад")
- })
- .foregroundColor(.white)
- Spacer()
- Button(action: { showingAlert = true }
- , label: {
- Image(systemName: "gear")
- })
- .foregroundColor(.white)
- .alert("Введите IP адрес сервера", isPresented: $showingAlert) {
- TextField("IP адрес сервера", text: $name)
- .foregroundColor(.black)
- Button("OK", action: submit)
- Button("Отмена", role: .cancel) { }
- }
- }.padding(.top, 5)
- }.padding(.top, 0)
- VStack {
- Image("Image")
- .resizable()
- .frame(width: whImg, height: whImg)
- .imageScale(.large)
- .foregroundStyle(.tint)
- if showLoading {
- VStack {
- VStack(spacing: 20) {
- ProgressView()
- Text(textLoading)
- }
- .background {
- RoundedRectangle(cornerRadius: 20)
- .fill(.black)
- .frame(width: 200, height: 200)
- }
- .offset(y: -70)
- }
- }
- Text(UIDevice.current.identifierForVendor!.uuidString)
- }
- }
- func load() {
- Сначала просто пытался сделать смену testBool.toggle()
- Не переходил. Пытался через Biling тоже не получается
- _ = fullScreenCover(isPresented: , content: {
- TestOnlineView()
- })
- }
- func submit() {
- print("You entered \(name)")
- if(name != "") {
- UserDefaults.standard.set(name, forKey: "ip_adres")
- urlStr = URL(string: name)!
- chatRoom.connect(url: urlStr, port: 2323)
- chatRoom.send(message: json)
- whImg = 200
- showLoading = true
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement