{"__v":58,"_id":"55f0c39e78661c170035e144","category":{"__v":12,"_id":"563d410f31f7580d00511e53","pages":["563d433c0bc2b80d00f30faf","563d436e656af00d00b759d7","563d43e38894d20d00014f6c","563d4403e79f670d00a10a64","563d442877681a0d00d969b8","56ba6b96984f030d00713aeb","56ba6c60c275570d00ce70c7","56ba6c6d8cf7c9210009671b","56ba6c7ece5d540d00e2d7ec","56ba6c8bb77e261700bc14d4","56bad43fb597f80d002f9777","56bad45db597f80d002f9779"],"project":"55f0757d4624ec2d00814345","version":"55f0b2b5f3735d0d00691ffe","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-11-07T00:08:47.065Z","from_sync":false,"order":3,"slug":"ios-sdk","title":"iOS SDK"},"parentDoc":null,"project":"55f0757d4624ec2d00814345","user":"55f0756a1e63fc37004b8d2b","version":{"__v":9,"_id":"55f0b2b5f3735d0d00691ffe","project":"55f0757d4624ec2d00814345","createdAt":"2015-09-09T22:29:09.118Z","releaseDate":"2015-09-09T22:29:09.118Z","categories":["55f0b2b5f3735d0d00691fff","55f0b2b5f3735d0d00692000","55f0b2b5f3735d0d00692001","55f0bd67d5d8fc0d00ca6f44","55f0cde9d5d8fc0d00ca6f55","563a8a62a8ba320d00106830","563a8ac9a8ba320d00106832","563d410f31f7580d00511e53","563d411de79f670d00a10a5f","563d412a31f7580d00511e54","566a206f74d574170070b640"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-09-09T23:41:18.763Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"The iOS SDK is a quick way to integrate secure messaging within a native iOS app. This quick start guide will help you get the SDK added to your project.  \n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"iOS Messenger Demo\",\n  \"body\": \"We put together an <a href=\\\"https://github.com/tigerconnect/ios-app-messenger-demo\\\" target=\\\"_blank\\\">iOS Messenger Demo</a> to help you get up to speed on how the iOS SDK works.  This demo app supports the Login, Inbox, Organizations and Conversation view modules.\\n\\nCheck it out here:\\n<a href=\\\"https://github.com/tigerconnect/ios-app-messenger-demo\\\" target=\\\"_blank\\\">https://github.com/tigerconnect/ios-app-messenger-demo</a>\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installation\"\n}\n[/block]\nThe TigerConnect iOS SDK can be installed directly into your application via CocoaPods which is our recommended path. CocoaPods provides a simple, versioned dependency management system that automates the tedious and error prone aspects of manually configuring libraries and frameworks.\n\nYou can add TigerConnect iOS SDK to your project via CocoaPods by doing the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ sudo gem install cocoapods\\n$ pod setup\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nNow create a Podfile in the root of your project directory and add the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pod \\\"TigerConnect\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nComplete the installation by executing:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ pod install\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"iOS SDK Requirements\",\n  \"body\": \"The following are requirements for the TigerConnect iOS SDK:\\nARC\\niOS7\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Initialization\"\n}\n[/block]\nImport the the TTKit library header in your AppDelegate.m.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import <TTKit/TTKit.h> \",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nThen initialize the SDK in your AppDelegate’s application.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[TTKit sharedInstance] initializeWithAgent:\\\"your_tigertext_agent\\\" environment:TTKitEnvironmentProduction];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nYou can validate TTKit is connected using the following command.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[TTKit sharedInstance] isUserConnected]\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Is there anything different about iOS 9?\",\n  \"body\": \"If you install on iOS 9 you need to this to your plist file:\\n\\n<key>NSAppTransportSecurity</key>\\n<dict>\\n  <key>NSAllowsArbitraryLoads</key>\\n  <true/>\\n  <key>NSExceptionDomains</key>\\n  <dict>\\n    <key>cloudfront.net</key>\\n    <dict>\\n      <key>NSIncludesSubdomains</key>\\n      <true/>\\n      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>\\n      <true/>\\n      <key>NSTemporaryExceptionMinimumTLSVersion</key>\\n      <string>1.0</string>\\n      <key>NSTemporaryExceptionRequiresForwardSecrecy</key>\\n      <false/>\\n    </dict>\\n    <key>tigertext.me</key>\\n    <dict>\\n      <key>NSExceptionAllowsInsecureHTTPLoads</key>\\n      <false/>\\n      <key>NSIncludesSubdomains</key>\\n      <true/>\\n    </dict>\\n  </dict>\\n</dict>\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"What if I am writing a Swift application?\",\n  \"body\": \"TTKit is an ObjC library, if you wish to run it in a swift project you will need to create a bridging header and add it to your build settings under Swift Compiler - Code Generation.  Please add to the bridging header - more details provided on [Apple's developer documentation](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html).\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Logging in\"\n}\n[/block]\nWhen you launch the iOS SDK demo app, you’ll be presented with a TigerTest login screen. The following code authenticates the user and effectively logs them in.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[TTKit sharedInstance] loginWithUserId::::at:::\\\"username\\\" password:@\\\"password\\\" \\n\\n  success:^(TTUser *user) { \\n    // Handle login. \\n  } failure:^(NSError *error) { \\n    // Handle failure. \\n  }];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Logging Out\"\n}\n[/block]\nTo logout from TTKit and deauthenticate the user, please use the following command:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[TTKit sharedInstance] logout]\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nLogging out of TTKit will delete all local data including message and attachments, it will also deauthenticate the user's key/secret pair.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Getting Recent Conversations\"\n}\n[/block]\nAfter authenticating, the SDK will fetch all the recent conversations associated with the user and persist them in our local datastore. We use NSFetchResultsControllers to get your messages and register for any changes.\n\nFor example, if you take a look at the iOS demo app, we use the following \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NSFetchResultsController for conversations:\\n\\nNSFetchResultsController  *fetchController = [[TTKit sharedInstance] rosterFetchControllerWithDelegate:self]; \\n\\nNSArray *conversationObjects = [fetchController fetchedObjects];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nTo receive updates from the fetchController, be sure to implement the NSFetchedResultsControllerDelegate protocol methods:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"(void)controllerDidChangeContent:(NSFetchedResultsController *) controller \\n\\n(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject \\n  atIndexPath:(NSIndexPath *)indexPath \\n  forChangeType:(NSFetchedResultsChangeType)type \\n  newIndexPath:(NSIndexPath *)newIndexPath\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Sending a Message\"\n}\n[/block]\nIf you have completed sending a TigerText message to Echobot, you should be able to see the conversation and send another message via the iOS SDK demo app. There are several ways to send a message. The following snippet is one way to send a message that has a lifetime of 60 minutes.\n\nFirst Create a TTMessageRequest object:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"TTMessageRequest *messageRequest = [[TTMessageRequest alloc] initWithRecipientToken:self.rosterEntry.target.token];\\nmessageRequest.messageText = text;\\nmessageRequest.timeToLive = kMessageTimeToLive;\\nmessageRequest.deleteOnRead = kDeleteOnRead;\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nThen Request TTKit to process the request:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[TTKit sharedInstance] sendMessageWithRequest:messageRequest\\ncompletion:^(TTMessage *message, NSError *error) {\\n}];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nTo send a message with attachments, please specify the mime type.  You can pass an NSData object or a file path to the data you wish to upload as the attachment (using the file path for larger files). The max attachment size is currently 10MB.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"messageRequest.attachmentData = data;\\nmessageRequest.attachmentMimeType = @\\\"image/jpeg\\\";\\n\\nmessageRequest.attachmentFilePath = @\\\"attachment_file_path\\\";\\nmessageRequest.attachmentMimeType = @\\\"image/jpeg\\\";\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]","excerpt":"A quick guide to the TigerConnect iOS SDK.","slug":"ios-quick-start","type":"basic","title":"Quick Start Quide"}

Quick Start Quide

A quick guide to the TigerConnect iOS SDK.

The iOS SDK is a quick way to integrate secure messaging within a native iOS app. This quick start guide will help you get the SDK added to your project. [block:callout] { "type": "info", "title": "iOS Messenger Demo", "body": "We put together an <a href=\"https://github.com/tigerconnect/ios-app-messenger-demo\" target=\"_blank\">iOS Messenger Demo</a> to help you get up to speed on how the iOS SDK works. This demo app supports the Login, Inbox, Organizations and Conversation view modules.\n\nCheck it out here:\n<a href=\"https://github.com/tigerconnect/ios-app-messenger-demo\" target=\"_blank\">https://github.com/tigerconnect/ios-app-messenger-demo</a>" } [/block] [block:api-header] { "type": "basic", "title": "Installation" } [/block] The TigerConnect iOS SDK can be installed directly into your application via CocoaPods which is our recommended path. CocoaPods provides a simple, versioned dependency management system that automates the tedious and error prone aspects of manually configuring libraries and frameworks. You can add TigerConnect iOS SDK to your project via CocoaPods by doing the following: [block:code] { "codes": [ { "code": "$ sudo gem install cocoapods\n$ pod setup", "language": "shell" } ] } [/block] Now create a Podfile in the root of your project directory and add the following: [block:code] { "codes": [ { "code": "pod \"TigerConnect\"", "language": "shell" } ] } [/block] Complete the installation by executing: [block:code] { "codes": [ { "code": "$ pod install", "language": "text" } ] } [/block] [block:callout] { "type": "info", "title": "iOS SDK Requirements", "body": "The following are requirements for the TigerConnect iOS SDK:\nARC\niOS7" } [/block] [block:api-header] { "type": "basic", "title": "Initialization" } [/block] Import the the TTKit library header in your AppDelegate.m. [block:code] { "codes": [ { "code": "#import <TTKit/TTKit.h> ", "language": "objectivec" } ] } [/block] Then initialize the SDK in your AppDelegate’s application. [block:code] { "codes": [ { "code": "[[TTKit sharedInstance] initializeWithAgent:\"your_tigertext_agent\" environment:TTKitEnvironmentProduction];", "language": "objectivec" } ] } [/block] You can validate TTKit is connected using the following command. [block:code] { "codes": [ { "code": "[[TTKit sharedInstance] isUserConnected]", "language": "objectivec" } ] } [/block] [block:callout] { "type": "warning", "title": "Is there anything different about iOS 9?", "body": "If you install on iOS 9 you need to this to your plist file:\n\n<key>NSAppTransportSecurity</key>\n<dict>\n <key>NSAllowsArbitraryLoads</key>\n <true/>\n <key>NSExceptionDomains</key>\n <dict>\n <key>cloudfront.net</key>\n <dict>\n <key>NSIncludesSubdomains</key>\n <true/>\n <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>\n <true/>\n <key>NSTemporaryExceptionMinimumTLSVersion</key>\n <string>1.0</string>\n <key>NSTemporaryExceptionRequiresForwardSecrecy</key>\n <false/>\n </dict>\n <key>tigertext.me</key>\n <dict>\n <key>NSExceptionAllowsInsecureHTTPLoads</key>\n <false/>\n <key>NSIncludesSubdomains</key>\n <true/>\n </dict>\n </dict>\n</dict>" } [/block] [block:callout] { "type": "warning", "title": "What if I am writing a Swift application?", "body": "TTKit is an ObjC library, if you wish to run it in a swift project you will need to create a bridging header and add it to your build settings under Swift Compiler - Code Generation. Please add to the bridging header - more details provided on [Apple's developer documentation](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html)." } [/block] [block:api-header] { "type": "basic", "title": "Logging in" } [/block] When you launch the iOS SDK demo app, you’ll be presented with a TigerTest login screen. The following code authenticates the user and effectively logs them in. [block:code] { "codes": [ { "code": "[[TTKit sharedInstance] loginWithUserId:@\"username\" password:@\"password\" \n\n success:^(TTUser *user) { \n // Handle login. \n } failure:^(NSError *error) { \n // Handle failure. \n }];", "language": "objectivec" } ] } [/block] [block:api-header] { "type": "basic", "title": "Logging Out" } [/block] To logout from TTKit and deauthenticate the user, please use the following command: [block:code] { "codes": [ { "code": "[[TTKit sharedInstance] logout]", "language": "objectivec" } ] } [/block] Logging out of TTKit will delete all local data including message and attachments, it will also deauthenticate the user's key/secret pair. [block:api-header] { "type": "basic", "title": "Getting Recent Conversations" } [/block] After authenticating, the SDK will fetch all the recent conversations associated with the user and persist them in our local datastore. We use NSFetchResultsControllers to get your messages and register for any changes. For example, if you take a look at the iOS demo app, we use the following [block:code] { "codes": [ { "code": "NSFetchResultsController for conversations:\n\nNSFetchResultsController *fetchController = [[TTKit sharedInstance] rosterFetchControllerWithDelegate:self]; \n\nNSArray *conversationObjects = [fetchController fetchedObjects];", "language": "objectivec" } ] } [/block] To receive updates from the fetchController, be sure to implement the NSFetchedResultsControllerDelegate protocol methods: [block:code] { "codes": [ { "code": "(void)controllerDidChangeContent:(NSFetchedResultsController *) controller \n\n(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject \n atIndexPath:(NSIndexPath *)indexPath \n forChangeType:(NSFetchedResultsChangeType)type \n newIndexPath:(NSIndexPath *)newIndexPath", "language": "objectivec" } ] } [/block] [block:api-header] { "type": "basic", "title": "Sending a Message" } [/block] If you have completed sending a TigerText message to Echobot, you should be able to see the conversation and send another message via the iOS SDK demo app. There are several ways to send a message. The following snippet is one way to send a message that has a lifetime of 60 minutes. First Create a TTMessageRequest object: [block:code] { "codes": [ { "code": "TTMessageRequest *messageRequest = [[TTMessageRequest alloc] initWithRecipientToken:self.rosterEntry.target.token];\nmessageRequest.messageText = text;\nmessageRequest.timeToLive = kMessageTimeToLive;\nmessageRequest.deleteOnRead = kDeleteOnRead;", "language": "objectivec" } ] } [/block] Then Request TTKit to process the request: [block:code] { "codes": [ { "code": "[[TTKit sharedInstance] sendMessageWithRequest:messageRequest\ncompletion:^(TTMessage *message, NSError *error) {\n}];", "language": "objectivec" } ] } [/block] To send a message with attachments, please specify the mime type. You can pass an NSData object or a file path to the data you wish to upload as the attachment (using the file path for larger files). The max attachment size is currently 10MB. [block:code] { "codes": [ { "code": "messageRequest.attachmentData = data;\nmessageRequest.attachmentMimeType = @\"image/jpeg\";\n\nmessageRequest.attachmentFilePath = @\"attachment_file_path\";\nmessageRequest.attachmentMimeType = @\"image/jpeg\";", "language": "objectivec" } ] } [/block]