{"__v":51,"_id":"5540d9f25cf9682100d61acf","category":{"__v":14,"_id":"5540d91bbb9e762d00f594ad","pages":["5540d9835cf9682100d61acc","5540d9f25cf9682100d61acf","55a3c52253611017004386bd","55a7744495bf6d25009a0505","55a8f59ac8bd450d000dd11f","55a8f945c8bd450d000dd128","55a8fb52c8bd450d000dd131","55a9046fc8bd450d000dd152","55a9094827a17d210052522a","55a90b6bcf45e1390093f2b8","55a90dd5c8bd450d000dd167","55a911afc8bd450d000dd179","55a9120acf45e1390093f2d0","55ba2eadb3612925009d670a"],"project":"5540ce1b31827a0d007ab1cc","version":"5540ce1c31827a0d007ab1cf","reference":false,"createdAt":"2015-04-29T13:14:03.694Z","from_sync":false,"order":3,"slug":"ios","title":"iOS"},"project":"5540ce1b31827a0d007ab1cc","user":"5540cdbf5cf9682100d61a97","version":{"__v":29,"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","createdAt":"2015-04-29T12:27:08.390Z","releaseDate":"2015-04-29T12:27:08.390Z","categories":["5540ce1c31827a0d007ab1d0","5540d91bbb9e762d00f594ad","5540e5f131827a0d007ab212","5540e5febb9e762d00f594d3","5540e61331827a0d007ab213","5540e6195cf9682100d61afa","5540e62631827a0d007ab214","5540e63031827a0d007ab215","5540e63531827a0d007ab216","5540e63e5cf9682100d61afc","5540e6445cf9682100d61afd","5540e64a5cf9682100d61afe","55a4ff5b2e70c0250038050f","55acb28318eefd0d0071d504","55ae1abe8576b92300291c80","55ae453ef302af23000ac109","55af586d555b900d0036d296","55af91dac8a85321007a53c3","55b9fee204775a2f00628071","55b9ff0e04775a2f00628072","55b9ff4604775a2f00628073","55b9ff5fd72d1e1900276a38","55b9ff7f04775a2f00628074","55b9ff90eb08801900f833e5","55b9ffa5d72d1e1900276a39","55b9ffca04775a2f00628075","55b9fffdd72d1e1900276a3a","56bc2f033ee9e70d008b46af","56c2f6efbbf9ec2d00e0fe4f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"createdAt":"2015-04-29T13:17:38.418Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[**Download iOS SDK**](https://github.com/Pushwoosh/pushwoosh-ios-sdk)\n[**Download Sample**](https://github.com/Pushwoosh/pushwoosh-ios-sdk/tree/master/Samples/iPhone)\n[**SDK API Docs**](https://github.com/Pushwoosh/pushwoosh-ios-sdk/tree/master/Documentation) \n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Simulator can neither subscribe nor receive push notifications.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"We are Cocoapods firendly\",\n  \"body\": \"Pushwoosh is available for Cocoapods: https://cocoapods.org/?q=pushwoosh\\n\\ntarget 'MyApp' do\\n  pod 'Pushwoosh'\\nend\"\n}\n[/block]\nTo integrate Pushwoosh into your application you need to do simple following steps:\n\n1. Add **Pushwoosh.framework** to your project.\n\n2. In your **Info.plist** add the following key `Pushwoosh_APPID` with your Pushwoosh Application ID string value\n\n3. Make the following changes to the code:\n\n3.1. Add the following import definitions to the **AppDelegate.m** file.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::import CoreLocation;\\n@import SystemConfiguration;\\n@import AVFoundation;\\n@import ImageIO;\\n \\n#import <Pushwoosh/PushNotificationManager.h>\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n3.2. Add the following code to the `didFinishLaunchingWithOptions` function.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\\n{\\n    //lots of your initialization code\\n \\n    //-----------PUSHWOOSH PART-----------\\n    // set custom delegate for push handling, in our case - view controller\\n    PushNotificationManager * pushManager = [PushNotificationManager pushManager];\\n    pushManager.delegate = self;\\n     \\n    // handling push on app start\\n    [[PushNotificationManager pushManager] handlePushReceived:launchOptions];\\n     \\n    // make sure we count app open in Pushwoosh stats\\n    [[PushNotificationManager pushManager] sendAppOpen];\\n     \\n    // register for push notifications!\\n    [[PushNotificationManager pushManager] registerForPushNotifications];\\n \\n    return YES;\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n3.3. Add the following code to your **UIApplicationDelegate** (same file as above).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// system push notification registration success callback, delegate to pushManager\\n- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {\\n    [[PushNotificationManager pushManager] handlePushRegistration:deviceToken];\\n}\\n \\n// system push notification registration error callback, delegate to pushManager\\n- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {\\n    [[PushNotificationManager pushManager] handlePushRegistrationFailure:error];\\n}\\n \\n// system push notifications callback, delegate to pushManager\\n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {\\n    [[PushNotificationManager pushManager] handlePushReceived:userInfo];\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n3.4. To handle push notifications add the following function to your **UIApplicationDelegate** (the same file as three steps above)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {\\n    NSLog(@\\\"Push notification received\\\");\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n3.5 Add **libz.dylib** to the project. To do so:\n\n* Go to Target section\n* Open \"Build Phases\" tab\n* Open \"Link Binaries With Libraries\"\n* Click on \"+\" button\n* Search \"libz.dylib\"\n* Click on add button\n\nRepeat the same process for **libstdc++.dylib** library.\nPlease note that on Xcode 7 **.dylib** files have **.tbd** extension.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"In order to ensure that Pushwoosh SDK always receives the push token it is highly recommended to enable the Remote notifications option from the Background modes section of the Capabilities tab in your Xcode project. You can also enable this support by including the `UIBackgroundModes` key with the `remote-notification` value in your app’s **Info.plist** file.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"If you would like to hide notification alerts when the app is in the foreground, simply set `Pushwoosh_SHOW_ALERT` value to `NO` in your **Info.plist**.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Controlling Log Level\",\n  \"body\": \"In order to assist with debugging and integration, SDK will print all the requests to the console by default. When you ready for the production build,  set \\\"*Pushwoosh_LOG_LEVEL*\\\" string key in your **Info.plist** file to one of the following values:\\n\\n*NONE* - No logs from the SDK\\n*ERROR* - Display only errors in the console\\n*WARNING* - Display also a warnings\\n*INFO* - Display informational messages\\n*DEBUG* - Even debug information is displayed now\\n*VERBOSE* - Everything SDK can print and more\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"For load balancing purposes we may need to change the API endpoints in your application. This happens automatically and handled by our SDK. **Please make sure that nothing in your app is blocking access to any URL that contains *.pushwoosh.com in it.**\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"If your device is connected to the Internet via WiFi, and messages don’t get through to the device, please **make sure APNs ports are not blocked by your firewall**.\\nPush providers, iOS devices, and Mac computers are often behind firewalls. To send notifications, you will need to allow inbound and outbound TCP packets over port 2195. Devices and computers connecting to the push service over **Wi-Fi will need to allow inbound and outbound TCP packets over port 5223**.\\nThe IP address range for the push service is subject to change; the expectation is that providers will connect by hostname rather than IP address. The push service uses a load balancing scheme that yields a different IP address for the same hostname. However, the entire 17.0.0.0/8 address block is assigned to Apple, so you can specify that range in your firewall rules.\",\n  \"title\": \"If you are behind Firewall or your WiFi router acts as a Firewall\"\n}\n[/block]","excerpt":"","slug":"native-ios-sdk","type":"basic","title":"Native iOS SDK"}
[**Download iOS SDK**](https://github.com/Pushwoosh/pushwoosh-ios-sdk) [**Download Sample**](https://github.com/Pushwoosh/pushwoosh-ios-sdk/tree/master/Samples/iPhone) [**SDK API Docs**](https://github.com/Pushwoosh/pushwoosh-ios-sdk/tree/master/Documentation) [block:callout] { "type": "info", "body": "Simulator can neither subscribe nor receive push notifications." } [/block] [block:callout] { "type": "success", "title": "We are Cocoapods firendly", "body": "Pushwoosh is available for Cocoapods: https://cocoapods.org/?q=pushwoosh\n\ntarget 'MyApp' do\n pod 'Pushwoosh'\nend" } [/block] To integrate Pushwoosh into your application you need to do simple following steps: 1. Add **Pushwoosh.framework** to your project. 2. In your **Info.plist** add the following key `Pushwoosh_APPID` with your Pushwoosh Application ID string value 3. Make the following changes to the code: 3.1. Add the following import definitions to the **AppDelegate.m** file. [block:code] { "codes": [ { "code": "@import CoreLocation;\n@import SystemConfiguration;\n@import AVFoundation;\n@import ImageIO;\n \n#import <Pushwoosh/PushNotificationManager.h>", "language": "objectivec" } ] } [/block] 3.2. Add the following code to the `didFinishLaunchingWithOptions` function. [block:code] { "codes": [ { "code": "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n{\n //lots of your initialization code\n \n //-----------PUSHWOOSH PART-----------\n // set custom delegate for push handling, in our case - view controller\n PushNotificationManager * pushManager = [PushNotificationManager pushManager];\n pushManager.delegate = self;\n \n // handling push on app start\n [[PushNotificationManager pushManager] handlePushReceived:launchOptions];\n \n // make sure we count app open in Pushwoosh stats\n [[PushNotificationManager pushManager] sendAppOpen];\n \n // register for push notifications!\n [[PushNotificationManager pushManager] registerForPushNotifications];\n \n return YES;\n}", "language": "objectivec" } ] } [/block] 3.3. Add the following code to your **UIApplicationDelegate** (same file as above). [block:code] { "codes": [ { "code": "// system push notification registration success callback, delegate to pushManager\n- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {\n [[PushNotificationManager pushManager] handlePushRegistration:deviceToken];\n}\n \n// system push notification registration error callback, delegate to pushManager\n- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {\n [[PushNotificationManager pushManager] handlePushRegistrationFailure:error];\n}\n \n// system push notifications callback, delegate to pushManager\n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {\n [[PushNotificationManager pushManager] handlePushReceived:userInfo];\n}", "language": "objectivec" } ] } [/block] 3.4. To handle push notifications add the following function to your **UIApplicationDelegate** (the same file as three steps above) [block:code] { "codes": [ { "code": "- (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {\n NSLog(@\"Push notification received\");\n}", "language": "objectivec" } ] } [/block] 3.5 Add **libz.dylib** to the project. To do so: * Go to Target section * Open "Build Phases" tab * Open "Link Binaries With Libraries" * Click on "+" button * Search "libz.dylib" * Click on add button Repeat the same process for **libstdc++.dylib** library. Please note that on Xcode 7 **.dylib** files have **.tbd** extension. [block:callout] { "type": "warning", "body": "In order to ensure that Pushwoosh SDK always receives the push token it is highly recommended to enable the Remote notifications option from the Background modes section of the Capabilities tab in your Xcode project. You can also enable this support by including the `UIBackgroundModes` key with the `remote-notification` value in your app’s **Info.plist** file." } [/block] [block:callout] { "type": "info", "body": "If you would like to hide notification alerts when the app is in the foreground, simply set `Pushwoosh_SHOW_ALERT` value to `NO` in your **Info.plist**." } [/block] [block:callout] { "type": "info", "title": "Controlling Log Level", "body": "In order to assist with debugging and integration, SDK will print all the requests to the console by default. When you ready for the production build, set \"*Pushwoosh_LOG_LEVEL*\" string key in your **Info.plist** file to one of the following values:\n\n*NONE* - No logs from the SDK\n*ERROR* - Display only errors in the console\n*WARNING* - Display also a warnings\n*INFO* - Display informational messages\n*DEBUG* - Even debug information is displayed now\n*VERBOSE* - Everything SDK can print and more" } [/block] [block:callout] { "type": "warning", "body": "For load balancing purposes we may need to change the API endpoints in your application. This happens automatically and handled by our SDK. **Please make sure that nothing in your app is blocking access to any URL that contains *.pushwoosh.com in it.**" } [/block] [block:callout] { "type": "info", "body": "If your device is connected to the Internet via WiFi, and messages don’t get through to the device, please **make sure APNs ports are not blocked by your firewall**.\nPush providers, iOS devices, and Mac computers are often behind firewalls. To send notifications, you will need to allow inbound and outbound TCP packets over port 2195. Devices and computers connecting to the push service over **Wi-Fi will need to allow inbound and outbound TCP packets over port 5223**.\nThe IP address range for the push service is subject to change; the expectation is that providers will connect by hostname rather than IP address. The push service uses a load balancing scheme that yields a different IP address for the same hostname. However, the entire 17.0.0.0/8 address block is assigned to Apple, so you can specify that range in your firewall rules.", "title": "If you are behind Firewall or your WiFi router acts as a Firewall" } [/block]