Skip to content

This is an iOS chat app. It uses iOS's MutliPeer Connectivity module. The module uses bluetooth and wifi to communicate with the nearby devices. The chat can connect up to 8 peers.

Notifications You must be signed in to change notification settings

morningbob/peerConnect_iOS_swiftUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Peer Connect

 

Peer Connect iOS mobile app

   

Peer Connect is an app which applies a Swift's extension, MultiPeer Connectivity, to let users chat with nearby devices. The extension uses bluetooth and wifi to make connections between devices.

 

The app starts to browse for the other devices when the user presses the start button. It also starts to advertise the user's device for the other device to know the user is available for connections.

 

The devices discovered will be displayed to the user. The user can choose up to 7 devices to connect. Then, the app will wait for all 7 devices to respond and navigate to the chat view. The user can end the chat anytime he wants. If the user is the one who initiates the chat, by pressing the end chat button, the user will disconnect all the peers, the chat will end. If the user is the one who accepts an invitation, by pressing the end chat button will disconnect him only. It won't affect the other peers. The group chat can continue. If all peers disconnected, the chat will be ended.

 

The app only permit one chat at anytime. If there are incoming connections during the chat, the user's device will refuse the connections automatically. It will accept connections again when the chat ended.

 

The chat is entirely peer to peer. There is no central server involved. I'm still thinking if I'll keep the chat records using Core Data.

 

I am still writing a function to send files, data between devices.

 

application home screenshot

 

Home screen    

choose peer screenshot

 

The app displays a list of peers that is available to connect. The user can select up to 7 peers.    

peer status screenshot

 

The app allows the peers to choose to accept or reject the connection.    

peer status screenshot

 

The app shows the status of the connections. If it is ready, the app will navigate to the chat view.    

peer status screenshot

 

The app also displays the connected peers and the group members in the chat view.    

Programming Style

 

  1. The app is written in SwiftUI. It follows Modern View Controller pattern.

  2. The connection manager class is used to deal with all connection related issues. It imports the Multipeer Connectivity module and use it to discover peers, advertise user device, connect peers, listen for incoming connections and send messages. The views retrieve peer status infomation and the chat messages from the connection manager to display to the user.

  3. The app makes use of the @observedObject and @environmentObject to listen for various updates from the connection manager. This is very important for this app because a lot functions depend on the change of the information from the connection. Like, the app will navigate to the chat view after the connection manager receive all responses to the invitations.

  4. In order to make it more convenient for the whole app to response to user initiated activities, I created an app state enum to represent different stages of the app. Most part of the app need to accomodate to different app states, like when to show an alert, when to end the chat, show who are connected with the user's device. Most of the time, the connection manager makes the decision of the change of the app states. Sometimes, the views decide, like the user press the end chat button, the app is changed to the end chat state.

  5. Although the chat messages are not sent to a server, I implemented the chat mechanism in a server and client manner. The user who initiates the chat is known as the server, the host. The host has connections with all the peers. But the peers don't connect to each other. When a peer, one of the client, send a message in the chat, the message is sent to the host only. The host then redirects the message to all the peers. It serves as a server in that sense.

  6. I made the app only handle one chat at a time. So, when there are incoming connections when the user is chatting, whether he is the host or the client, the app automatically refuses all incoming connections. I may make the app handles two chats at a time later.

  7. I will implement the function for the user to send files to peer devices later. I will also store the chat records in the device locally using Core Data.

  8. Please leave me comments for the project. Thank you very much!

All rights reserved.

About

This is an iOS chat app. It uses iOS's MutliPeer Connectivity module. The module uses bluetooth and wifi to communicate with the nearby devices. The chat can connect up to 8 peers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages