{"__v":15,"_id":"546b2a222abdeb08005c4b45","api":{"basic_auth":false,"params":[],"results":{"codes":[]},"try":true,"url":"","auth":"never"},"body":"[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Installing the SDK\",\n  \"body\": \"This walkthrough already assumes that you have installed the SDK and already have a registered organisation in the CMS, if this is not the case please visit http://proxitee.com/developers/ which has a guide for performing these actions.\"\n}\n[/block]\n# Required iBeacon settings\n\nIf you want to use iBeacons there are some standard settings that must be setup, firstly you must enable Background Modes under the Capabilities tab and enable both Location Updates and Acts as a Bluetooth LE accessory:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/bBi1DWlSQVqXZ0OuQ3mk_Screen%20Shot%202014-11-18%20at%2011.34.53%20AM.png\",\n        \"Screen Shot 2014-11-18 at 11.34.53 AM.png\",\n        \"1079\",\n        \"588\",\n        \"#263e6f\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nYou also need to Add a setting under the Info tab:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/lwItfzXZTpiDRjc3UHYQ_Screen%20Shot%202014-11-18%20at%2011.44.29%20AM.png\",\n        \"Screen Shot 2014-11-18 at 11.44.29 AM.png\",\n        \"1081\",\n        \"406\",\n        \"#94401e\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nUnder Required device capabilities make sure bluetooth-le is added.\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"iOS 8 and above\",\n  \"body\": \"Starting from iOS 8 Location Services has changed and now requires that a new setting be added to the Info settings, for further information visit http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/\"\n}\n[/block]\n# Required proxitee settings\n\nIn order to provide the necessary config for proxitee you must create a Proxitee.plist file in your project, this file should have this format:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<!DOCTYPE plist PUBLIC \\\"-//Apple//DTD PLIST 1.0//EN\\\" \\\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\\">\\n<plist version=\\\"1.0\\\">\\n<dict>\\n\\t<key>apiUrl</key>\\n\\t<string>http://beta-api.proxitee.com/v1/</string>\\n\\t<key>apiKey</key>\\n\\t<string>b35e23d774f86a03</string>\\n</dict>\\n</plist>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nYou will need to replace the apiKey with the API key issued when registering on the CMS and can be located on the Organisation screen.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"API URL\",\n  \"body\": \"This will be replaced depending on which environment you will be running against at present there is only a beta API available however there will also be a production API that will use https://api.proxitee.com/v1/\"\n}\n[/block]\n# Now for some code\n\nAll of the API interaction happens through the `PXTProxitee` class and acts as a facade for each of the tasks that can be carried out.\n\nThe first task is to setup the API this is typically done in the App Delegate for the application, in here you will first need to `import PXTProxitee.h` then perform the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"-(instancetype)init\\n{\\n    [PXTProxitee setup];\\n    return [super init];\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nNow we can start responding to beacons by adding the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\\n  \\t// in this example we only use beacons  \\n    [[PXTProxitee shared].beacons start];\\n    return YES;\\n}\\n\\n- (void)applicationWillTerminate:(UIApplication *)application {\\n    [[PXTProxitee shared].beacons stop];\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nAt the moment the app will not do a lot as we have no custom actions registered and no notifications we are observing for.\n\nNext we will listen for a notification of when beacons are received then we can see if there being captured by proxitee.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"CMS Setup\",\n  \"body\": \"In order for the beacons to be received they will need to be already setup inside the CMS, for more details on using the CMS please visit http://proxitee-cms.readme.io/\"\n}\n[/block]\nNotifications can be managed using `[PXTProxitee shared].notifications` and use a subclass of `NSNotificationCenter` so the API should already be familiar:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"-(void)receivedBeacons:(NSNotification *)notification {\\n\\t\\tNSArray *beacons = [notification.userInfo objectForKey::::at:::\\\"beacons\\\"];\\n  \\tNSLog(@\\\"received beacons: %@\\\", beacons);\\n}\\n\\n-(void)dealloc\\n{\\n    [[PXTProxitee shared].notifications removeObserver:self];\\n}\\n\\n// add this inside of didFinishLaunchingWithOptions\\n[[PXTProxitee shared].notifications addObserver:self selector:@selector(receivedBeacons:) name:kPXTBeaconManagerDidReceiveBeaconsNotification object:nil];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nThat's it for this walkthrough you should now have your app being able to respond to beacons setup in the proxitee CMS, go ahead and add a local notification action and assign it to one of your beacons, you should see the notification when the app is either in the background or closed.","category":"546b2a212abdeb08005c4b43","createdAt":"2014-11-18T11:14:42.637Z","excerpt":"A walkthrough of getting up to speed with using the iOS SDK","githubsync":"","hidden":false,"link_external":false,"link_url":"","order":0,"project":"546b2a212abdeb08005c4b3f","slug":"getting-started","sync_unique":"","title":"Getting started","type":"basic","updates":[],"user":"5469f4baa3b67a0e00559b47","version":"546b2a212abdeb08005c4b42","childrenPages":[]}

Getting started

A walkthrough of getting up to speed with using the iOS SDK

[block:callout] { "type": "warning", "title": "Installing the SDK", "body": "This walkthrough already assumes that you have installed the SDK and already have a registered organisation in the CMS, if this is not the case please visit http://proxitee.com/developers/ which has a guide for performing these actions." } [/block] # Required iBeacon settings If you want to use iBeacons there are some standard settings that must be setup, firstly you must enable Background Modes under the Capabilities tab and enable both Location Updates and Acts as a Bluetooth LE accessory: [block:image] { "images": [ { "image": [ "https://files.readme.io/bBi1DWlSQVqXZ0OuQ3mk_Screen%20Shot%202014-11-18%20at%2011.34.53%20AM.png", "Screen Shot 2014-11-18 at 11.34.53 AM.png", "1079", "588", "#263e6f", "" ] } ] } [/block] You also need to Add a setting under the Info tab: [block:image] { "images": [ { "image": [ "https://files.readme.io/lwItfzXZTpiDRjc3UHYQ_Screen%20Shot%202014-11-18%20at%2011.44.29%20AM.png", "Screen Shot 2014-11-18 at 11.44.29 AM.png", "1081", "406", "#94401e", "" ] } ] } [/block] Under Required device capabilities make sure bluetooth-le is added. [block:callout] { "type": "danger", "title": "iOS 8 and above", "body": "Starting from iOS 8 Location Services has changed and now requires that a new setting be added to the Info settings, for further information visit http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/" } [/block] # Required proxitee settings In order to provide the necessary config for proxitee you must create a Proxitee.plist file in your project, this file should have this format: [block:code] { "codes": [ { "code": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>apiUrl</key>\n\t<string>http://beta-api.proxitee.com/v1/</string>\n\t<key>apiKey</key>\n\t<string>b35e23d774f86a03</string>\n</dict>\n</plist>", "language": "xml" } ] } [/block] You will need to replace the apiKey with the API key issued when registering on the CMS and can be located on the Organisation screen. [block:callout] { "type": "info", "title": "API URL", "body": "This will be replaced depending on which environment you will be running against at present there is only a beta API available however there will also be a production API that will use https://api.proxitee.com/v1/" } [/block] # Now for some code All of the API interaction happens through the `PXTProxitee` class and acts as a facade for each of the tasks that can be carried out. The first task is to setup the API this is typically done in the App Delegate for the application, in here you will first need to `import PXTProxitee.h` then perform the following: [block:code] { "codes": [ { "code": "-(instancetype)init\n{\n [PXTProxitee setup];\n return [super init];\n}", "language": "objectivec" } ] } [/block] Now we can start responding to beacons by adding the following: [block:code] { "codes": [ { "code": "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n \t// in this example we only use beacons \n [[PXTProxitee shared].beacons start];\n return YES;\n}\n\n- (void)applicationWillTerminate:(UIApplication *)application {\n [[PXTProxitee shared].beacons stop];\n}", "language": "objectivec" } ] } [/block] At the moment the app will not do a lot as we have no custom actions registered and no notifications we are observing for. Next we will listen for a notification of when beacons are received then we can see if there being captured by proxitee. [block:callout] { "type": "warning", "title": "CMS Setup", "body": "In order for the beacons to be received they will need to be already setup inside the CMS, for more details on using the CMS please visit http://proxitee-cms.readme.io/" } [/block] Notifications can be managed using `[PXTProxitee shared].notifications` and use a subclass of `NSNotificationCenter` so the API should already be familiar: [block:code] { "codes": [ { "code": "-(void)receivedBeacons:(NSNotification *)notification {\n\t\tNSArray *beacons = [notification.userInfo objectForKey:@\"beacons\"];\n \tNSLog(@\"received beacons: %@\", beacons);\n}\n\n-(void)dealloc\n{\n [[PXTProxitee shared].notifications removeObserver:self];\n}\n\n// add this inside of didFinishLaunchingWithOptions\n[[PXTProxitee shared].notifications addObserver:self selector:@selector(receivedBeacons:) name:kPXTBeaconManagerDidReceiveBeaconsNotification object:nil];", "language": "objectivec" } ] } [/block] That's it for this walkthrough you should now have your app being able to respond to beacons setup in the proxitee CMS, go ahead and add a local notification action and assign it to one of your beacons, you should see the notification when the app is either in the background or closed.