In v1.3 of Socialize we introduced push notifications. This provides your app with a simple and effective way to bring users back into the “viral loop” of the app.
when a user posts a comment they can elect to subscribe to updates for that topic.
When another user then posts a comment, the original user will receive a push notification to their device bringing them back into the app.
for Push Notifications to work they must be enabled on a compatible plan at http://getsocialize.com/apps
Select your app and click “SmartAlerts Settings”
Then turn on enabled:
Find your App ID in the Apple’s developer portal here: https://developer.apple.com/ios/manage/bundles/index.action> . Then click ‘Configure’ on the right-hand side.
Make sure “Enable for Apple Push Notification service” is checked.
Follow the directions given to you by Apple very carefully.
Note
Note
It is important to note that just creating or updating your Apple Push Notification Service certificate will not update your provisioning profile. Therefore make sure to re-create your distribution provisioning profile for your changes to take effect.
Double-clicking the certificate(.cer) should automatically open the ‘Keychain Access’ tool.
If you’ve added a password to your p12 make sure to put that in.
To configure your app you’ll need to register for notifications, handle the notification response and define an entity loader so we display users your content.
Add the following line to your application delegate:
//import the socialize header
#import <Socialize/Socialize.h>
#pragma mark
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Register for Apple Push Notification Service
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
//your application specific code
return YES;
}
To register your app’s device token add the following lines to your application’s delegate
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken
{
#if !DEBUG
[Socialize registerDeviceToken:deviceToken];
#endif
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Handle Socialize notification at foreground
if ([Socialize handleNotification:userInfo]) {
NSLog(@"Socialize handled the notification on foreground");
return;
}
NSLog(@"Socialize did not handle the notification on foreground");
}
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// ...
// Register for Apple Push Notification Service
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
// Handle Socialize notification at launch
NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil) {
if ([Socialize handleNotification:userInfo]) {
NSLog(@"Socialize handled the notification on app launch.");
} else {
NSLog(@"Socialize did not handle the notification on app launch.");
}
}
//your application specific code
return YES;
}
Note
For Smart Alerts to work correctly, you must define an entity loader.
Defining an Entity Loader allows Socialize’s UI objects to link back to your application’s objects.
Copy the lines below to add an entity loader
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// ...
// Register for Apple Push Notification Service
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
// Handle Socialize notification at launch
NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil) {
if ([Socialize handleNotification:userInfo]) {
NSLog(@"Socialize handled the notification on app launch.");
} else {
NSLog(@"Socialize did not handle the notification on app launch.");
}
}
// Specify a Socialize entity loader block
[Socialize setEntityLoaderBlock:^(UINavigationController *navigationController, id<SocializeEntity>entity) {
SampleEntityLoader *entityLoader = [[[SampleEntityLoader alloc] initWithEntity:entity] autorelease];
[navigationController pushViewController:entityLoader animated:YES];
}];
return YES;
}
For some applications, it might happen that an entities are not always available. Socialize provides the ability to selectively disable loading for a given entity. Should you find you need this, you can do this by defining a “Can Load Entity” block, as follows
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// ...
[Socialize setCanLoadEntityBlock:^BOOL(id<SocializeEntity> entity) {
return ![entity.name isEqualToString:@"DeletedEntity"];
}];
return YES;
}
In order to test that SmartAlerts™ are working correctly you’ll want to first to get your app compiled and installed on a physical device and working on the simulator as well.
Note
The subscribe button will only show on an actual device. If you do not see the button on the device, please refer to the Troubleshooting section below.
If you would like to send a target alert your users, you can do so. Simply click “Send SmartAlert” from the developer dashboard. You can direct the user to either a specific entity or a URL of your choosing. Directing to an entity will trigger your entity loader. Directing to a URL will send the user to a web view to a URL of your choosing. You can either target all of your users or specify a comma-separated list of user ids.
Note
Socialize v1.6 or later is required to receive target SmartAlerts
If you are not receiving notifications, there are some simple ways to troubleshoot problems. We also have a vibrant developer community and support here: http://support.getsocialize.com support who can help.
Additionally, here some common errors you might encounter:
The notifications button will only appear if a valid push token has been registered with Socialize using [Socialize registerDeviceToken:]. This means the buttons will never show on the iOS simulator.
If you do not see the buttons on the actual device, you might try making sure there are no errors with registration process, as described in the next section.
You can implement the notifications delegate method which callbacks if any error occurs during registration. This should log the value of the error to your console.
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Error Register Notifications: %@", [error localizedDescription]);
}
This typically means you didn’t re-create and download the provisioning profile after you enabled pushed notifications. You can re-create your distribution profile here: https://developer.apple.com/ios/manage/provisioningprofiles/viewDistributionProfiles.action. You’ll also want to remove any other versions of provisioning file which exist on your phone.
You can try sending a push directly to your device. You can open the device logs from Xcode by attaching your device, selecting Window -> Organizer, choosing your device, and selecting “Console”. The message is
Mar 28 12:16:57 AppName[3354]: Socialize: device token FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF successfully registered with server
You can then send a notification from the web interface, in the “View Debugger” section of the web interface.
One possibility is that Socialize has received a development push token. Development tokens will currently prevent pushes being sent to real devices. Until Socialize automatically clears these on error, you should verify that you do not send development tokens to Socialize using [Socialize registerDeviceToken:]
As a precaution, you might wrap the registration call as follows:
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken
{
#if !DEBUG
[Socialize registerDeviceToken:deviceToken];
#endif
}
This is only a problem if you already have separate push configurations and certificates for development and distribution. Socialize itself does not support development push.
Please go to support.getsocialize.com for additional support.