{"id":5162,"date":"2021-08-24T14:00:33","date_gmt":"2021-08-24T14:00:33","guid":{"rendered":"https:\/\/www.voxer.com\/blog\/?p=5162"},"modified":"2021-08-24T14:35:04","modified_gmt":"2021-08-24T14:35:04","slug":"how-to-add-live-audio-to-your-ios-application-with-voxer-sdk","status":"publish","type":"post","link":"https:\/\/www.voxer.com\/blog\/how-to-add-live-audio-to-your-ios-application-with-voxer-sdk\/","title":{"rendered":"How to add live audio to your iOS application with Voxer SDK"},"content":{"rendered":"<p><span style=\"font-family: helvetica, arial, sans-serif\">Over the past 18 months, nearly every company has had to to deal with the rapid transition to remote work. This has created a wave of increased user needs for both asynchronous and synchronous communication features that offer the connectivity and flexibility needed in todays digital landscape. Integrating live audio communication and other modern messaging tools into your own application is easier than ever with Voxer SDK. Within minutes you can send audio and text messages to a group of users and enable an external Push-to-talk button so that audio messages can be sent any time, and played even when your app is the background.<\/span><\/p>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Using the Voxer SDK, the complexity of adding synchronous and asynchronous communication is dramatically simplified. Here&#8217;s how you can add communication features easily to your iOS application.<\/span><\/p>\n<h2><span style=\"font-family: helvetica, arial, sans-serif;color: #ff6600\"><strong>Requirements<\/strong><\/span><\/h2>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">&#8211; A Voxer SDK developer account (link to sign up)<br \/>\n<\/span><span style=\"font-family: helvetica, arial, sans-serif\">&#8211; A deployment target of iOS 11<br \/>\n<\/span><span style=\"font-family: helvetica, arial, sans-serif\">&#8211; Xcode 12.5<br \/>\n<\/span><span style=\"font-family: helvetica, arial, sans-serif\">&#8211; CocoaPods<\/span><\/p>\n<h2><span style=\"font-family: helvetica, arial, sans-serif;color: #ff6600\">Setup<\/span><\/h2>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Let&#8217;s start by configuring your Xcode project. Create or start with an already existing iOS project in Xcode and add the VoxerKit.xcramework to your project. Under your project make sure &#8220;Embeded &amp; Sign&#8221; is selected by going to General ? Targets ? Frameworks, Libraries and Embedded Content. Next, Go to your project &#8220;Build Settings&#8221; -&gt; &#8220;Excluded Architectures&#8221; -&gt; Add &#8220;Any iOS Simulator SDK&#8221; with the value &#8220;arm64&#8221; (for Debug And Release). Lastly, In &#8220;Signing &amp; Capabilities&#8221; add &#8220;Background Modes&#8221; and then select &#8220;Audio, AirPlay, and Picture in Picture&#8221; and &#8220;Voice over IP&#8221;.<\/span><\/p>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Once your Xcode project is configured, we can now initialize the Voxer SDK by adding the following snippet:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code class=\"language-jsx\">let voxer: Voxer = Voxer(isBackgroundAudioEnable: true)\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Now we can add authentication by logging into the Voxer network with:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>voxer.loginWith(username: username, password: password) { [weak self] response in\r\n  if response == .success {\r\n    print (\"Login suceeded\")\r\n  } else {\r\n    print (\"Login failed\")\r\n  }\r\n}\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">You can check if a user is already logged in with the following:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>if voxer.loggedInUsername?.isEmpty == false {\r\n  \/\/ User already logged from previous session.\r\n}\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Now that you have initialized the Voxer SDK and logged into the Voxer network, you can now start a chat with a group of users, send text and audio messages, and enable Walkie-Talkie mode.<\/span><\/p>\n<h2><span style=\"font-family: helvetica, arial, sans-serif;color: #ff6600\">Enable External Push-to-talk (PTT) Button?<\/span><\/h2>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">You can now enable an external PTT button feature called <strong>Walkie Talkie Mode<\/strong> that allows allows your app to record and send audio messages any time rather your app is in the foreground or &#8220;running&#8221; in the background.?<\/span><\/p>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Notes: if your app is suspended in the background, Walkie Talkie mode does not work.<\/span><\/p>\n<h4><span style=\"font-family: helvetica, arial, sans-serif\">Enable Walkie Talkie<\/span><\/h4>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>if voxer.enableWalkieTalkie(for: chatId) != true {\r\n    print(\"ERROR: Could not enable walkie talkie for chat.id: (chatId)\")\r\n}\r\n<\/code><\/span><\/pre>\n<h4><span style=\"font-family: helvetica, arial, sans-serif\">Disable Walkie Talkie<\/span><\/h4>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>if voxer.disableWalkieTalkie(for: chatId) != true {\r\n    print(\"ERROR: Could not disable walkie talkie for chat.id: (chatId)\")\r\n}\r\n<\/code><\/span><\/pre>\n<h4><span style=\"font-family: helvetica, arial, sans-serif\">Get Current Walkie Talkie Chat<\/span><\/h4>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>let chatId = voxer.getWalkieTalkieChatId()\r\n<\/code><\/span><\/pre>\n<h4><span style=\"font-family: helvetica, arial, sans-serif\">Talk with Walkie Talkie Mode<\/span><\/h4>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">The first call to this method starts recording the audio and sends it. The second call to this method will stop the audio recording.<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>let toggleSuccess = voxer.toggleWalkieTalkie { (error) in\r\n    print(\"ERROR: Recording failed for walkie talkie.\")\r\n}\r\n<\/code><\/span><\/pre>\n<h2><span style=\"font-family: helvetica, arial, sans-serif;color: #ff6600\">Conclusion<\/span><\/h2>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Congratulations! You have now added live audio to your application with a few lines of code using the Voxer SDK. If you don&#8217;t have access to a Voxer Developer Portal you can sign up to join the beta program here: <a href=\"https:\/\/get.voxer.com\/sdk\/\">https:\/\/get.voxer.com\/sdk\/<\/a><\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the past 18 months, nearly every company has had to to deal with the rapid transition to remote work&#8230;<\/p>\n","protected":false},"author":3,"featured_media":5165,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[179,103,4897,179904,481072746,286819650],"tags":[659313399,128577,659313400],"yst_prominent_words":[659311642,659311949,659313403,659313414,659313413,659313410,659313404,659311801,659311452,659313392,659313405,659312640,659313409,659313402,659311410,659313407,659313391,659311535,659312635,659313406],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/posts\/5162"}],"collection":[{"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/comments?post=5162"}],"version-history":[{"count":4,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/posts\/5162\/revisions"}],"predecessor-version":[{"id":5172,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/posts\/5162\/revisions\/5172"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/media\/5165"}],"wp:attachment":[{"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/media?parent=5162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/categories?post=5162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/tags?post=5162"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=5162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}