{"_id":"5c73f7dc0e6b33005113d0cb","project":"54aa7f773b56130b0056c86e","version":{"_id":"55781fe25129590d003ff4f7","project":"54aa7f773b56130b0056c86e","forked_from":"54aa7f773b56130b0056c871","__v":8,"createdAt":"2015-06-10T11:30:42.700Z","releaseDate":"2015-06-10T11:30:42.700Z","categories":["55781fe35129590d003ff4f8","55781fe35129590d003ff4f9","55781fe35129590d003ff4fa","55781fe35129590d003ff4fb","55781fe35129590d003ff4fc","55781fe35129590d003ff4fd","55781fe35129590d003ff4fe","564bbc7e8841060d00abb2ee","565b66c446118c0d00dcb0bb","56898269f8dc340d00308c13","582318b23b961a0f009516a1","594a848c9f4771001a43c959","5c73dd27e8fdc000572a206a","5c77ac5af94a920045cb80ca"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Developers","version_clean":"2.0.0","version":"2.0"},"category":{"_id":"5c77ac5af94a920045cb80ca","project":"54aa7f773b56130b0056c86e","version":"55781fe25129590d003ff4f7","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2019-02-28T09:39:38.102Z","from_sync":false,"order":5,"slug":"react","title":"React Native SDK"},"user":"57bc3654b9c7f0220009c77b","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2019-02-25T14:12:44.339Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"Before reading this guide make sure that you have properly setup your React App using our guide under - https://pulsate.readme.io/v2.0/docs/installing-the-react-plugin\n\nThis guide will take you through all the steps that are needed to properly setup your iOS App and run the Pulsate SDK.\n[block:api-header]\n{\n  \"title\": \"1. Setup CocoaPods\"\n}\n[/block]\nCocoaPods is built in Ruby and you can install it with the Terminal:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ sudo gem install cocoapods\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nAfter you install CocoaPods, you can setup the files needed to integrate by going to your XCode project folder and running:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ pod init\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"2. Installing dependencies\"\n}\n[/block]\nThe last step should produce the *Podfile* file, where you declare all your dependencies. Open the newly created *Podfile*, remove everything except the main target bracket and under the main target add\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# Uncomment the next line to define a global platform for your project\\n# platform :ios, '9.0'\\n\\ntarget 'TargetName' do\\n    # Uncomment the next line if you're using Swift or would like to use dynamic frameworks\\n    # use_frameworks!\\n\\n    # Pods for TargetName\\n    pod 'React', :path => '../node_modules/react-native'\\n    pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'\\n    pod 'RNPulsateSdkReact', :path => '../node_modules/pulsate-react-native-sdk/ios'\\nend\\n\\npost_install do |installer|\\n    installer.pods_project.targets.each do |target|\\n        if target.name == \\\"React\\\"\\n            target.remove_from_project\\n        end\\n    end\\nend\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"After integrating CocoaPods with your project, please remember to always use the \\\\*.xcworkspace file, not \\\\*.xcodeproj to open your project.\",\n  \"title\": \"iOS Workspace\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Updating your pods\",\n  \"body\": \"You can update your pods by using:\\n\\n*$ pod update*\\n\\nPlease be careful when updating the PULPulsate pod. It'll overwrite all the UI and language customizations you might have in your PULPulsateBasic.bundle. Please keep a copy of your customizations when updating.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"3. Adding CoreLocation Authorization Key\"\n}\n[/block]\niOS 8.0 and later requires adding \"NSLocationAlwaysUsageDescription\" to your *.plist file for CoreLocation to work.\niOS 11 and later requires adding the \"NSLocationAlwaysAndWhenInUseUsageDescription\" and \"NSLocationWhenInUseUsageDescription\" keys.\n\nAdd all three keys to your project’s *Info.plist* containing the message to be displayed to the user at the prompt. For example \"We use this to provide the best experience possible inside our store. We also send relevant communications based on your location.\"\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/d44fb27-7783492-2017-09-19_11.57.22_am.png\",\n        \"7783492-2017-09-19_11.57.22_am.png\",\n        1756,\n        154,\n        \"#dcdede\"\n      ],\n      \"caption\": \"\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"If your app already has the *When In Use* permission, there's no way to show the location prompt second time. The only way for the users to update the permission from *When In Use* to *Always* is in the settings. You can open the settings for the user programatically:\\n\\n `NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];`\\n `[[UIApplication sharedApplication] openURL:url];`\\n\\n or send them a campaign with `app-settings:` deeplink.\",\n  \"title\": \"When In Use Permission\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"4. Running Pulsate\"\n}\n[/block]\nWith our dependencies added we can now run Pulsate.\nSearch for the* AppDelegate.m* file and open it. To properly run Pulsate add the following code\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId::::at:::\\\"APP_ID\\\" andAppKey:@\\\"APP_KEY\\\" validationError:nil];\\n    PULPulsateManager* manager = [PULPulsateFactory getInstanceWithAuthorizationData:authData withLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions withPulsateAppDelegate:YES andPulsateNotificationDelegate:YES error:nil];\\n    [manager startPulsateSession:^(BOOL success, NSError * _Nullable error) {\\n\\n    }];\",\n      \"language\": \"cplusplus\"\n    }\n  ]\n}\n[/block]\n*APP_ID* and *APP_KEY* are used to associate the Pulsate SDK with your Pulsate Web Application which you have created using our Pulsate Web Console. *APP_ID* and *APP_KEY* can be found in your application configuration panel. To find them open admin panel, and then go to *Settings -> App Settings* screen in the Pulsate web console.\n[block:api-header]\n{\n  \"title\": \"5. Building and Running the App\"\n}\n[/block]\nIf you have any problems with the project not building or problems with the App not running properly do the following steps\n- Delete *Pods* file\n- Delete *node_modules*\n- Run *npm install* in the main folder\n- Run pod install in the ios folde\n\nIf you still have problems run the following\n- *watchman watch-del-all*\n- *rm -fr $TMPDIR/react-**\n- *rm -rf node_modules*\n- *npm install*\n- *npm cache clean*\n- *npm start -- --reset-cache*\n- Also try to download the latest node js and run - *npm install -g npm*","excerpt":"","slug":"setting-up-the-pulsate-react-sdk-ios","type":"basic","title":"Setting up the Pulsate React SDK - iOS"}

Setting up the Pulsate React SDK - iOS


Before reading this guide make sure that you have properly setup your React App using our guide under - https://pulsate.readme.io/v2.0/docs/installing-the-react-plugin This guide will take you through all the steps that are needed to properly setup your iOS App and run the Pulsate SDK. [block:api-header] { "title": "1. Setup CocoaPods" } [/block] CocoaPods is built in Ruby and you can install it with the Terminal: [block:code] { "codes": [ { "code": "$ sudo gem install cocoapods", "language": "shell" } ] } [/block] After you install CocoaPods, you can setup the files needed to integrate by going to your XCode project folder and running: [block:code] { "codes": [ { "code": "$ pod init", "language": "shell" } ] } [/block] [block:api-header] { "title": "2. Installing dependencies" } [/block] The last step should produce the *Podfile* file, where you declare all your dependencies. Open the newly created *Podfile*, remove everything except the main target bracket and under the main target add [block:code] { "codes": [ { "code": "# Uncomment the next line to define a global platform for your project\n# platform :ios, '9.0'\n\ntarget 'TargetName' do\n # Uncomment the next line if you're using Swift or would like to use dynamic frameworks\n # use_frameworks!\n\n # Pods for TargetName\n pod 'React', :path => '../node_modules/react-native'\n pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'\n pod 'RNPulsateSdkReact', :path => '../node_modules/pulsate-react-native-sdk/ios'\nend\n\npost_install do |installer|\n installer.pods_project.targets.each do |target|\n if target.name == \"React\"\n target.remove_from_project\n end\n end\nend", "language": "text" } ] } [/block] [block:callout] { "type": "info", "body": "After integrating CocoaPods with your project, please remember to always use the \\*.xcworkspace file, not \\*.xcodeproj to open your project.", "title": "iOS Workspace" } [/block] [block:callout] { "type": "danger", "title": "Updating your pods", "body": "You can update your pods by using:\n\n*$ pod update*\n\nPlease be careful when updating the PULPulsate pod. It'll overwrite all the UI and language customizations you might have in your PULPulsateBasic.bundle. Please keep a copy of your customizations when updating." } [/block] [block:api-header] { "title": "3. Adding CoreLocation Authorization Key" } [/block] iOS 8.0 and later requires adding "NSLocationAlwaysUsageDescription" to your *.plist file for CoreLocation to work. iOS 11 and later requires adding the "NSLocationAlwaysAndWhenInUseUsageDescription" and "NSLocationWhenInUseUsageDescription" keys. Add all three keys to your project’s *Info.plist* containing the message to be displayed to the user at the prompt. For example "We use this to provide the best experience possible inside our store. We also send relevant communications based on your location." [block:image] { "images": [ { "image": [ "https://files.readme.io/d44fb27-7783492-2017-09-19_11.57.22_am.png", "7783492-2017-09-19_11.57.22_am.png", 1756, 154, "#dcdede" ], "caption": "" } ] } [/block] [block:callout] { "type": "warning", "body": "If your app already has the *When In Use* permission, there's no way to show the location prompt second time. The only way for the users to update the permission from *When In Use* to *Always* is in the settings. You can open the settings for the user programatically:\n\n `NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];`\n `[[UIApplication sharedApplication] openURL:url];`\n\n or send them a campaign with `app-settings:` deeplink.", "title": "When In Use Permission" } [/block] [block:api-header] { "title": "4. Running Pulsate" } [/block] With our dependencies added we can now run Pulsate. Search for the* AppDelegate.m* file and open it. To properly run Pulsate add the following code [block:code] { "codes": [ { "code": "PULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@\"APP_ID\" andAppKey:@\"APP_KEY\" validationError:nil];\n PULPulsateManager* manager = [PULPulsateFactory getInstanceWithAuthorizationData:authData withLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions withPulsateAppDelegate:YES andPulsateNotificationDelegate:YES error:nil];\n [manager startPulsateSession:^(BOOL success, NSError * _Nullable error) {\n\n }];", "language": "cplusplus" } ] } [/block] *APP_ID* and *APP_KEY* are used to associate the Pulsate SDK with your Pulsate Web Application which you have created using our Pulsate Web Console. *APP_ID* and *APP_KEY* can be found in your application configuration panel. To find them open admin panel, and then go to *Settings -> App Settings* screen in the Pulsate web console. [block:api-header] { "title": "5. Building and Running the App" } [/block] If you have any problems with the project not building or problems with the App not running properly do the following steps - Delete *Pods* file - Delete *node_modules* - Run *npm install* in the main folder - Run pod install in the ios folde If you still have problems run the following - *watchman watch-del-all* - *rm -fr $TMPDIR/react-** - *rm -rf node_modules* - *npm install* - *npm cache clean* - *npm start -- --reset-cache* - Also try to download the latest node js and run - *npm install -g npm*