{"_id":"5540d9f25cf9682100d61acf","version":{"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","__v":31,"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","57595bbb18760817001e8bbe","57d8d9793916800e003dde53"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"user":"5540cdbf5cf9682100d61a97","category":{"_id":"5540d91bbb9e762d00f594ad","project":"5540ce1b31827a0d007ab1cc","version":"5540ce1c31827a0d007ab1cf","__v":14,"pages":["5540d9835cf9682100d61acc","5540d9f25cf9682100d61acf","55a3c52253611017004386bd","55a7744495bf6d25009a0505","55a8f59ac8bd450d000dd11f","55a8f945c8bd450d000dd128","55a8fb52c8bd450d000dd131","55a9046fc8bd450d000dd152","55a9094827a17d210052522a","55a90b6bcf45e1390093f2b8","55a90dd5c8bd450d000dd167","55a911afc8bd450d000dd179","55a9120acf45e1390093f2d0","55ba2eadb3612925009d670a"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-29T13:14:03.694Z","from_sync":false,"order":3,"slug":"ios","title":"iOS"},"parentDoc":null,"__v":57,"project":"5540ce1b31827a0d007ab1cc","updates":["578dea5a2948410e00dd39c6"],"next":{"pages":[],"description":""},"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 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]\nTo integrate Pushwoosh into your application follow these simple steps:\n\n**1.** Add **Pushwoosh.framework** to your project.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"target 'MyApp' do\\n\\tpod 'Pushwoosh'\\nend\",\n      \"language\": \"text\",\n      \"name\": \"Podfile\"\n    },\n    {\n      \"code\": \"github \\\"Pushwoosh/pushwoosh-ios-sdk\\\"\",\n      \"language\": \"text\",\n      \"name\": \"Cartfile\"\n    }\n  ]\n}\n[/block]\n**2.** Add **libz** and **libstdc++** to the project.\n\n* go to Target section\n* open \"Build Phases\" tab\n* open \"Link Binaries With Libraries\"\n* click on \"+\" button\n* search \"libz.tbd\"\n* click on add button\n* Repeat the same process for libstdc++.tbd library.\n\n**3.** In your **Info.plist** add the `Pushwoosh_APPID` key with your Pushwoosh Application ID string value\n\n**4.** Add following code to your AppDelegate:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import Pushwoosh\\nimport UserNotifications\\n\\n:::at:::UIApplicationMain\\nclass AppDelegate: UIResponder, UIApplicationDelegate, PushNotificationDelegate {\\n\\n  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {\\n\\t\\t//lots of initialization code\\n  \\n  \\t// set custom delegate for push handling, in our case AppDelegate\\n    PushNotificationManager.push().delegate = self\\n    \\n    // set default Pushwoosh delegate for iOS10 foreground push handling\\n    if #available(iOS 10.0, *) {\\n      UNUserNotificationCenter.current().delegate = PushNotificationManager.push().notificationCenterDelegate\\n    }\\n    \\n    // track application open statistics\\n    PushNotificationManager.push().sendAppOpen()\\n    \\n    // register for push notifications!\\n    PushNotificationManager.push().registerForPushNotifications()\\n    \\n    return true\\n  }\\n  \\n  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\\n    PushNotificationManager.push().handlePushRegistration(deviceToken as Data!)\\n  }\\n  \\n  func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {\\n    PushNotificationManager.push().handlePushRegistrationFailure(error)\\n  }\\n  \\n\\tfunc application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],\\n\\t                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {\\n\\t\\tPushNotificationManager.push().handlePushReceived(userInfo)\\n\\t\\tcompletionHandler(UIBackgroundFetchResult.noData)\\n\\t}\\n}\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"#import <Pushwoosh/PushNotificationManager.h>\\n#import <UserNotifications/UserNotifications.h>\\n\\n@implementation AppDelegate\\n\\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\\n    //lots of initialization code\\n\\n    // set custom delegate for push handling, in our case AppDelegate\\n    PushNotificationManager * pushManager = [PushNotificationManager pushManager];\\n    pushManager.delegate = self;\\n     \\n\\t\\t// set default Pushwoosh delegate for iOS10 foreground push handling\\n\\t\\t[UNUserNotificationCenter currentNotificationCenter].delegate = [PushNotificationManager pushManager].notificationCenterDelegate;\\n     \\n    // track application open statistics\\n    [[PushNotificationManager pushManager] sendAppOpen];\\n     \\n    // register for push notifications!\\n    [[PushNotificationManager pushManager] registerForPushNotifications];\\n \\n    return YES;\\n}\\n\\n// 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 fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {\\n    [[PushNotificationManager pushManager] handlePushReceived:userInfo];\\n    completionHandler(UIBackgroundFetchResultNoData);\\n}\\n\\n@end\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nTo handle push notifications add the following function to your **PushNotificationDelegate**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// this event is fired when the push is received in the app\\nfunc onPushReceived(_ pushManager: PushNotificationManager!, withNotification pushNotification: [AnyHashable : Any]!, onStart: Bool) {\\n\\t\\tprint(\\\"Push notification received: \\\\(pushNotification)\\\")\\n    // shows a push is received. Implement passive reaction to a push, such as UI update or data download.\\n}\\n\\n// this event is fired when user clicks on notification\\nfunc onPushAccepted(_ pushManager: PushNotificationManager!, withNotification pushNotification: [AnyHashable : Any]!, onStart: Bool) {\\n\\t\\tprint(\\\"Push notification accepted: \\\\(pushNotification)\\\")\\n    // shows a user tapped the notification. Implement user interaction, such as showing push details\\n}\\n\",\n      \"language\": \"swift\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"// this event is fired when the push is received in the app\\n- (void)onPushReceived:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {\\n    NSLog(@\\\"Push notification received\\\");\\n    // shows a push is received. Implement passive reaction to a push, such as UI update or data download.\\n}\\n\\n// this event is fired when user clicks on notification\\n- (void)onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {\\n    NSLog(@\\\"Push notification accepted\\\");\\n    // shows a user tapped the notification. Implement user interaction, such as showing push details\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n**5.** Enable **Push Notifications** in the **Capabilities** section.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/2726836-Screen_Shot_2016-09-20_at_14.39.50.png\",\n        \"Screen Shot 2016-09-20 at 14.39.50.png\",\n        751,\n        181,\n        \"#d8d7d2\"\n      ]\n    }\n  ]\n}\n[/block]\n**6.** Enable *\"Remote notifications\"* for **Background Modes** in the **Capabilities** section.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/c1d05a8-PushNotificationsApp_xcodeproj.png\",\n        \"PushNotificationsApp_xcodeproj.png\",\n        1408,\n        554,\n        \"#cccec9\"\n      ]\n    }\n  ]\n}\n[/block]\n**7.** To take advantage of automatic test device registration make sure your app is compatible with **Test Devices** as outlined here:\n[http://docs.pushwoosh.com/docs/test-devices#ios](http://docs.pushwoosh.com/docs/test-devices#ios)\n\nThat’s it!","excerpt":"","slug":"native-ios-sdk","type":"basic","title":"iOS SDK"}
[**Download 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] To integrate Pushwoosh into your application follow these simple steps: **1.** Add **Pushwoosh.framework** to your project. [block:code] { "codes": [ { "code": "target 'MyApp' do\n\tpod 'Pushwoosh'\nend", "language": "text", "name": "Podfile" }, { "code": "github \"Pushwoosh/pushwoosh-ios-sdk\"", "language": "text", "name": "Cartfile" } ] } [/block] **2.** Add **libz** and **libstdc++** to the project. * go to Target section * open "Build Phases" tab * open "Link Binaries With Libraries" * click on "+" button * search "libz.tbd" * click on add button * Repeat the same process for libstdc++.tbd library. **3.** In your **Info.plist** add the `Pushwoosh_APPID` key with your Pushwoosh Application ID string value **4.** Add following code to your AppDelegate: [block:code] { "codes": [ { "code": "import Pushwoosh\nimport UserNotifications\n\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate, PushNotificationDelegate {\n\n func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {\n\t\t//lots of initialization code\n \n \t// set custom delegate for push handling, in our case AppDelegate\n PushNotificationManager.push().delegate = self\n \n // set default Pushwoosh delegate for iOS10 foreground push handling\n if #available(iOS 10.0, *) {\n UNUserNotificationCenter.current().delegate = PushNotificationManager.push().notificationCenterDelegate\n }\n \n // track application open statistics\n PushNotificationManager.push().sendAppOpen()\n \n // register for push notifications!\n PushNotificationManager.push().registerForPushNotifications()\n \n return true\n }\n \n func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\n PushNotificationManager.push().handlePushRegistration(deviceToken as Data!)\n }\n \n func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {\n PushNotificationManager.push().handlePushRegistrationFailure(error)\n }\n \n\tfunc application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],\n\t fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {\n\t\tPushNotificationManager.push().handlePushReceived(userInfo)\n\t\tcompletionHandler(UIBackgroundFetchResult.noData)\n\t}\n}", "language": "swift" }, { "code": "#import <Pushwoosh/PushNotificationManager.h>\n#import <UserNotifications/UserNotifications.h>\n\n@implementation AppDelegate\n\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n //lots of initialization code\n\n // set custom delegate for push handling, in our case AppDelegate\n PushNotificationManager * pushManager = [PushNotificationManager pushManager];\n pushManager.delegate = self;\n \n\t\t// set default Pushwoosh delegate for iOS10 foreground push handling\n\t\t[UNUserNotificationCenter currentNotificationCenter].delegate = [PushNotificationManager pushManager].notificationCenterDelegate;\n \n // track application open statistics\n [[PushNotificationManager pushManager] sendAppOpen];\n \n // register for push notifications!\n [[PushNotificationManager pushManager] registerForPushNotifications];\n \n return YES;\n}\n\n// 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 fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {\n [[PushNotificationManager pushManager] handlePushReceived:userInfo];\n completionHandler(UIBackgroundFetchResultNoData);\n}\n\n@end", "language": "objectivec" } ] } [/block] To handle push notifications add the following function to your **PushNotificationDelegate** [block:code] { "codes": [ { "code": "// this event is fired when the push is received in the app\nfunc onPushReceived(_ pushManager: PushNotificationManager!, withNotification pushNotification: [AnyHashable : Any]!, onStart: Bool) {\n\t\tprint(\"Push notification received: \\(pushNotification)\")\n // shows a push is received. Implement passive reaction to a push, such as UI update or data download.\n}\n\n// this event is fired when user clicks on notification\nfunc onPushAccepted(_ pushManager: PushNotificationManager!, withNotification pushNotification: [AnyHashable : Any]!, onStart: Bool) {\n\t\tprint(\"Push notification accepted: \\(pushNotification)\")\n // shows a user tapped the notification. Implement user interaction, such as showing push details\n}\n", "language": "swift", "name": "Swift" }, { "code": "// this event is fired when the push is received in the app\n- (void)onPushReceived:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {\n NSLog(@\"Push notification received\");\n // shows a push is received. Implement passive reaction to a push, such as UI update or data download.\n}\n\n// this event is fired when user clicks on notification\n- (void)onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {\n NSLog(@\"Push notification accepted\");\n // shows a user tapped the notification. Implement user interaction, such as showing push details\n}", "language": "objectivec" } ] } [/block] **5.** Enable **Push Notifications** in the **Capabilities** section. [block:image] { "images": [ { "image": [ "https://files.readme.io/2726836-Screen_Shot_2016-09-20_at_14.39.50.png", "Screen Shot 2016-09-20 at 14.39.50.png", 751, 181, "#d8d7d2" ] } ] } [/block] **6.** Enable *"Remote notifications"* for **Background Modes** in the **Capabilities** section. [block:image] { "images": [ { "image": [ "https://files.readme.io/c1d05a8-PushNotificationsApp_xcodeproj.png", "PushNotificationsApp_xcodeproj.png", 1408, 554, "#cccec9" ] } ] } [/block] **7.** To take advantage of automatic test device registration make sure your app is compatible with **Test Devices** as outlined here: [http://docs.pushwoosh.com/docs/test-devices#ios](http://docs.pushwoosh.com/docs/test-devices#ios) That’s it!