Delite Studio
Five-star iPhone, iPad, Android, and OS X apps
    • Home
    • WordPress
      • Push Notifications for WordPress
        • Documentation
        • FAQs
        • Library for iOS
        • Library for Android
    • Apps
      • Picture Transfer
      • Local Cloud
        • For iOS
        • For Android
      • File Storage
      • File Transfer
        • For iOS
        • For Mac
        • For Android
        • For Windows
      • File Extractor
      • Localizable Strings Merge
      • Delite Blocks
    • About
    • Contact
    • Account
      • Cart
    • enEnglish
      • itItaliano
    Select Page ...

    Push Notifications library for iOS

    ← Back to Push Notifications for WordPress

    Download the Library

    Here is the library to register for push notifications on your website running Push Notifications for WordPress and receive them:

    • Push Notifications for iOS

    Adding to your project

    Now that you've downloaded the library, you're ready to add it to your own project. Here's what you do:

    1. Open your project in Xcode.
    2. Navigate with Finder to where you uncompressed the library and drag the PushNotifications.framework folder into your project in Xcode.
    3. Make sure Copy items ... is selected.
    4. Press Finish button.

    Build your application. If you encounter an error, double-check the steps above. If it runs without error, you're ready to integrate push notifications.

    Integrate Push Notifications into Your App Delegate

    To simplify the integration of Push Notifications for WordPress in your iOS app follow these steps:

    1. Import the <PushNotifications/PushNotifications.h> header.
    2. Make the AppDelegate conform the DSRestClientDelegate protocol.
    3. Add the @property (nonatomic, strong) DSRestClient *restClient; in the AppDelegate interface:
      @interface AppDelegate () <DSRestClientDelegate>
      @property (nonatomic, strong) DSRestClient *restClient;
      @end
    4. In the application:didFinishLaunchingWithOptions: method add these lines of code:
      if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
      	[[UIApplication sharedApplication]
      		registerUserNotificationSettings:[UIUserNotificationSettings
      		settingsForTypes:(
      			UIUserNotificationTypeSound |
      			UIUserNotificationTypeAlert |
      			UIUserNotificationTypeBadge)
      		categories:nil]];
      	[[UIApplication sharedApplication] registerForRemoteNotifications];
      } else {
      	[[UIApplication sharedApplication]
      		registerForRemoteNotificationTypes:(
      			UIRemoteNotificationTypeBadge |
      			UIRemoteNotificationTypeSound |
      			UIRemoteNotificationTypeAlert)];
      }
      
    5. Implement the application:didRegisterForRemoteNotificationsWithDeviceToken: and application:didFailToRegisterForRemoteNotificationsWithError: methods:
      - (void)application:(UIApplication *)application 	
      	didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
      	// Important note: If the user restores backup data to a new device or computer,
      	// or reinstalls the operating system, the device token changes.
      	self.restClient = [[DSRestClient alloc] init];
      	self.restClient.delegate = self;
      	[self.restClient registerWithUrl:@"http://[SERVER]/pnfw/register/"
      		andToken:deviceToken];
      }
      
      - (void)application:(UIApplication *)application
      	didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
      	// Manage failure
      }

      Where [SERVER] is the domain of the server where you have previously installed and configured Push Notifications for WordPress.
      You can enable OAuth request signing using:

      self.restClient = [[DSRestClient alloc] initWithKey:@"[CONSUMER_KEY]"
      	andSecret:@"[CONSUMER_SECRET]"];
    6. Implement the DSRestClientDelegate methods, including: restClientRegistered: and restClient:registerFailedWithError:.

    Adding the "-ObjC" Linker Flag

    1. Select the project file from the project navigator on the far left side of the window.
    2. Select the target for where you want to add the linker flag.
    3. Select the Build Settings tab
      Choose All to show all Build Settings.
    4. Scroll down to the Linking section, and double-click to the right of where it says Other Linker Flags.
    5. A box will appear, Click on the + button to add a new linker flag.
    6. Type -ObjC and press enter.

    Disable Bitcode option

    1. Select the project file from the project navigator on the far left side of the window.
    2. Select the target for where you want to disable Bitcode option.
    3. Select the Build Settings tab
      Choose All to show all Build Settings.
    4. Scroll down to the Build Options section, click to the right of where it says Enable Bitcode and set it to No.

    App Transport Security Notes (iOS 9 or later)

    iOS 9.0 has an "App Transport Security" which encourages developers to use HTTPS instead of HTTP (more info here).

    If your server is not protected by HTTPS by default you'll get the error: "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."

    You should add an exception for specific domains in your Info.plist:

    <key>NSAppTransportSecurity</key>
    <dict>
    	<key>NSExceptionDomains</key>
    	<dict>
    		<key>yourdomain.com</key>
    		<dict>
    			<key>NSExceptionAllowsInsecureHTTPLoads</key>
    			<true/>
    			<key>NSIncludesSubdomains</key>
    			<true/>
    		</dict>
    	</dict>
    </dict>

    Receiving Push Notifications

    You can retrieve notification data with the following code in the AppDelegate:

    - (void)application:(UIApplication *)application
    	didReceiveRemoteNotification:(NSDictionary *)userInfo {
    	// This method is called if the app is running in the foreground, but also
    	// if the user press "show" on the notification AND the app is in the background
    	
    	NSDictionary *aps = userInfo[@"aps"];
    	NSString *title = aps[@"alert"];
    	NSString *eventId = userInfo[@"id"];
    
    	if (application.applicationState == UIApplicationStateActive) {
    		// If the application is foremost and visible when the system delivers the notification,
    		// no alert is shown, no icon is badged, and no sound is played. So we need to display a
    		// notification to the user when the app is actually running in the foreground
    		...
    		show an alert
    		...
    	}
    	else {
    		// App was just brought from background to foreground because the user tapped on the notification
    		...
    		do something with id and title
    		...
    	}
    }

    Subscribing

    This method allows client device to subscribe itself on the server. A user is created with the specified email address and role "App Subscriber." A welcome email is automatically sent to that address with the login details. If an app subscriber was already registered with that email address it is no longer created, but it is associated with the new token.

    restClient.delegate = self;
    [restClient linkWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/register/"
    	andEmail:email];

    Those delegate methods are called:

    - (void)restClientLinked:(DSRestClient *)client
    	withEmail:(NSString *)email
    	andCustomParameters:(NSDictionary *)customParameters;
    
    - (void)restClient:(DSRestClient *)client
    	linkFailedWithError:(NSError *)error;

    You can add any custom fields to subscribers using the hook pnfw_register_custom_parameters and use this method:

    restClient.delegate = self;
    [restClient linkWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/register/"
    	andEmail:email
    	andCustomParameters:@{@"key": value}];

    Unregistering

    This method allows client device to unregister itself from push notifications. If the last token associated with an anonymous user is removed, the user is also removed.

    restClient.delegate = self;
    [restClient unregisterWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/unregister/"];

    Those delegate methods are called:

    - (void)restClientUnregistered:(DSRestClient *)client;
    
    - (void)restClient:(DSRestClient *)client
    	unregisterFailedWithError:(NSError *)error;

    Retrieving Posts

    This method returns a list of posts filtered for the saved device token (i.e. user/device). For each post are returned only basic information.

    NSDate *timestamp = nil;
    restClient.delegate = self;
    [restClient loadPostsWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/posts/"
    	andTimestamp:timestamp];

    Those delegate methods are called:

    - (void)restClient:(DSRestClient *)client
    	loadedPosts:(PNPosts *)posts;
    
    - (void)restClientPostsUnchanged:(DSRestClient *)client;
    
    - (void)restClient:(DSRestClient *)client
    	loadPostsFailedWithError:(NSError *)error;

    Retrieving specific Post

    This method returns the details of the specified post.

    restClient.delegate = self;
    [restClient loadPostWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/posts/"
    	andIdentifier:identifier];

    Those delegate methods are called:

    - (void)restClient:(DSRestClient *)client
    	loadedPost:(PNPost *)post;
    
    - (void)restClientPostUnchanged:(DSRestClient *)client;
    
    - (void)restClient:(DSRestClient *)client
    	loadPostFailedWithError:(NSError *)error;

    Retrieving Categories

    This method allows client device to retrieve the list of post categories.

    NSDate *timestamp = nil;
    restClient.delegate = self;
    [restClient loadCategoriesWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/categories/"
    	andTimestamp:timestamp;

    Those delegate methods are called:

    - (void)restClient:(DSRestClient *)client
    	loadedCategories:(PNCategories *)categories;
    
    - (void)restClientCategoriesUnchanged:(DSRestClient *)client;
    
    - (void)restClient:(DSRestClient *)client
    	loadCategoriesFailedWithError:(NSError *)error;

    Updating Categories

    This method allows client device to set posts categories of which wants to receive push notifications.

    restClient.delegate = self;
    [restClient updateCategoryWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/categories/"
    	andIdentifier:identifier
    	andExclude:exclude;

    Those delegate methods are called:

    - (void)restClientCategoryUpdated:(DSRestClient *)client;
    
    - (void)restClient:(DSRestClient *)client
    	updateCategoryFailedWithError:(NSError *)error;

    Retrieving User Categories

    This method allows client device to retrieve the list of user categories.

    NSDate *timestamp = nil;
    restClient.delegate = self;
    [restClient loadUserCategoriesWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/user-categories/"
    	andTimestamp:timestamp];

    Those delegate methods are called:

    - (void)restClient:(DSRestClient *)client
    	loadedUserCategories:(PNUserCategories *)categories;
    
    - (void)restClientUserCategoriesUnchanged:(DSRestClient *)client;
    
    - (void)restClient:(DSRestClient *)client
    	loadUserCategoriesFailedWithError:(NSError *)error;

    Updating User Categories

    This method allows client device to set user categories.

    restClient.delegate = self;
    [restClient updateUserCategoryWithUrl:@"http://[YOUR WORDPRESS SERVER]/pnfw/user-categories/"
    	andIdentifier:identifier];

    Those delegate methods are called:

    - (void)restClientUserCategoryUpdated:(DSRestClient *)client;
    
    - (void)restClient:(DSRestClient *)client
    	updateUserCategoryFailedWithError:(NSError *)error;
  • Push Notifications for WordPress

    • Documentation
    • FAQs
    • What are the differences between Push Notifications for WordPress and Push Notifications for WordPress (LITE)?
    • Features
    • Changelog
    • Configuring iOS Push Notifications
    • Configuring Android Push Notifications
    • Configuring Safari Push Notifications
    • Configuring Chrome Push Notifications
    • Push Notifications library for iOS
    • Push Notifications library for Android
    • Local Cloud for iOS

      Local Cloud for iOS
      iPad / iPhone / Mac / Windows
      Picture Transfer for iOS

      Picture Transfer for iOS
      iPad / iPhone / Mac / Windows
      File Transfer for Mac

      File Transfer for Mac
      Mac
    Delite Studio S.r.l. © 2011 - 2018. All Rights Reserved. — P. IVA e Cod. Fisc. IT03402240042 — Privacy Policy
    We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkMore info