18
Build a WhatsApp clone in 2 hours Startup Weekend Bootcamp - powered by skygear.io David Ng (Product Manager at Skygear)

How to build a Whatsapp clone in 2 hours

Embed Size (px)

Citation preview

Page 1: How to build a Whatsapp clone in 2 hours

Build a WhatsApp clone in 2 hoursStartup Weekend Bootcamp - powered by skygear.io

David Ng (Product Manager at Skygear)

Page 2: How to build a Whatsapp clone in 2 hours

Agenda

• Getting hands on how to build a WhatsApp-like mobile application.

• What skills do you need.

• … and tools you need.

• Some code to show.

Page 3: How to build a Whatsapp clone in 2 hours

What skills do I need?

• User Experience (UX) design

• Mobile side programming

• Server side programming

Page 4: How to build a Whatsapp clone in 2 hours

WhatsApp’s Stack

Page 5: How to build a Whatsapp clone in 2 hours

What it is and what it is not

• It is a technical discussion on what you can do to build WhatsApp-like Chat app with limited resources.

• It is not what we encourage cloning other’s product.

• It is not you can build what all WhatsApp now supports in 2 hours.

Page 6: How to build a Whatsapp clone in 2 hours

Features that an ideal chat app must have

• Security

• Real time connectivity

• Group conversations

• Presence indicators

Page 7: How to build a Whatsapp clone in 2 hours

What’s in WhatsApp first version

• Signing up

• Conversation List

• Creating Conversations (1-on-1 and Group Chat)

• Message List

• Send and receive messages

Page 8: How to build a Whatsapp clone in 2 hours

Skygear

• An open-source project in Hong Kong

• Managed Hosting at skygear.io

• Commercial Support available

• Written in Go

Page 9: How to build a Whatsapp clone in 2 hours

Setup

• Sign up your chat server at skygear.io

• Obtain your Server endpoint and API Key in the INFO tab

Page 10: How to build a Whatsapp clone in 2 hours

Setting up the project

• Open a new Xcode Project

• pod init

• Update Podfile

• pod install

pod 'JSQMessagesViewController', '~> 7.3.4' pod 'MBProgressHUD', '~> 1.0.0' pod 'SKYKit', :git => 'https://github.com/SkygearIO/skygear-SDK-iOS.git', :commit => '4516b15' pod 'SKYKitChat', :git => 'https://github.com/SkygearIO/chat-SDK-iOS.git', :commit => '08235f2'

Page 11: How to build a Whatsapp clone in 2 hours

Frontend

• We are using JSQMessagesViewController for the front-end UI

Page 12: How to build a Whatsapp clone in 2 hours

Configure Skygear Endpoint for your App

• Config these lines to connect to Skygear Server

• Your app will then be connected to the cloud!

SKYContainer.default().configAddress("<Your endpoint url>")SKYContainer.default().configure(withAPIKey: "<Your API Key>")

Page 13: How to build a Whatsapp clone in 2 hours

Signing up your user

• We can use the signup API in Skygear to signup a user

SKYContainer.default().signup(withEmail: emailField.text, password: passwordField.text) { (user, error) inif (error != nil) { self.showAlert(error as! NSError) return}print("Signed up as: \(user)")}

Page 14: How to build a Whatsapp clone in 2 hours

Conversation List

func fetchUserConversations(completion: (() -> Void)?) { chat?.fetchUserConversations { (conversations, error) in if let err = error { let alert = UIAlertController(title: "Unable to load conversations", message: err.localizedDescription, preferredStyle: UIAlertControllerStyle.alert) self.present(alert, animated: true, completion: nil) return }

if let fetchedConversations = conversations { print("Fetched \(fetchedConversations.count) user conversations.") self.conversations = fetchedConversations } }

Page 15: How to build a Whatsapp clone in 2 hours

Creating Conversations

• the CreateConversation APIchat?.createConversation(participantIDs: viewController.participantIDs, title: title, metadata: nil, completion: { (userConversation, error) in hud.hide(animated: true) if error != nil { return }})

Page 16: How to build a Whatsapp clone in 2 hours

Message List chat.fetchMessages(conversation: conversation.conversation, limit: 100, beforeTime: nil, completion: { (messages, error) in if let err = error { return }

if let messages = messages { self.messages = messages.reversed() } })

Page 17: How to build a Whatsapp clone in 2 hours

Send and receive messages

let message = SKYMessage()! message.body = text message.creatorUserRecordID = SKYContainer.default().currentUserRecordID chat.addMessage(message, to: (conversation?.conversation)!, completion: { (msg, _) in if let sentMessage = msg { guard let transientMessageIndex = self.messages.index(of: message) else { return }}

Page 18: How to build a Whatsapp clone in 2 hours

Summary

• It takes much less effort to build a full-featured chat app.

• Utilize good resources to make it easier.