PushApps gives you the ability to focus on the important and unique issues in your app, by taking care of all the push notification issues for you. That being said, we know that the ability to control on your incoming push messages is an important thing. And exactly for that we've created the PushApps delegate.

 

 

Icon

The methods in the PushAppsDelegate, are all optional.

Handle Notifications

If this method was called, it indicates the user either press the received notification or was inside the app. Either ways, the user can get the information you wanted to deliver. A best practice would be to make a specific action, e.g: take him to a specific page inside the app. 

- (void)pushApps:(PushAppsManager *)manager didReceiveRemoteNotification:(NSDictionary *)pushNotification whileInForeground:(BOOL)inForeground

TypeNameDescription
PushAppsManager

manager

The PushAppsManager instance.
NSDictionary

pushNotification

A NSDictionary, contains all the information about the push message - the "aps" object (contains the alert, badge and sound properties), your custom properties (if configured) and also the PushApps custom properties (e.g.: Link).
BOOL

inForeground

Indicates if the app were in foreground while receiving the message.

Example:

 

1
2
3
4
5
6
7
- (void)pushApps:(PushAppsManager *)manager didReceiveRemoteNotification:(NSDictionary *)pushNotification whileInForeground:(BOOL)inForeground
{
    // This method is being called on each incoming push message. It does not matter if the app is opened or closed, in foreground or not - 
    // this is where you'll be notify about it!
}

 

Custom JSON Handeling


If you created a custom JSON object to pass extra info to your users, which may contain a link to a video, we have created a working example for you.

Lets assume that your app is all about football. When ever a goal is scored, your users receive a Push Notification regarding their favorite team. You wish to notify them about the goal, and provide them with the means to view this goal. You will create a custom JSON object that would probably look like this:

custom JSON

 

{
    "Data": // the key which you input in Push Apps Admin Console
    {
        "last_goal_link" : "http: //www.some.url.com" // the value you input in Push Apps Admin Console
    }
}

 

When the Push Notification arrives, you will get notified by the delegate method. An option to handle this custom JSON could look like this:

Handling Custom JSON with PushAppsManagerDelegate

 

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
- (void)pushApps:(PushAppsManager *)manager didReceiveRemoteNotification:(NSDictionary *)pushNotification whileInForeground:(BOOL)inForeground
{
     
    // you will need to pass a pushDictionary and the customJsonKey you have specified in the web service.
    [self extractInfoFromCustomJson:pushNotification withCustomJsonKey:@"Data"];
     
}
 
#define LAST_CUSTOM_JSON_KEY @"my.last.custom.json"
- (void)extractInfoFromCustomJson:(NSDictionary *)pushDictionary withCustomJsonKey:(NSString *)customJsonKey
{
    NSString *customJsonString = pushDictionary[customJsonKey];
     
    if (customJsonString) { // if the JSON exists
         
        // we will convert it to get a 'clean' NSDictionary
        NSData *customJsonData = [customJsonString dataUsingEncoding:NSUTF8StringEncoding];
         
        id json = [NSJSONSerialization JSONObjectWithData:customJsonData options:0 error:nil];
         
        NSDictionary *customJson;
         
        if ([json isKindOfClass:[NSDictionary class]]) {
             
            customJson = (NSDictionary *)json;
             
        }
         
        if (customJson) {
             
            // if all is well, and we have the dictionary, we will save the dictionary to use it when we want to, and post a notification.
            [[NSUserDefaults standardUserDefaults] setObject:customJson forKey:LAST_CUSTOM_JSON_KEY];
            [[NSUserDefaults standardUserDefaults] synchronize];
             
            [[NSNotificationCenter defaultCenter] postNotificationName:@"PushAppsNewPushReceivedNotification" object:nil];
        }
    }
}

 

Now, we should prepare an implementation for the custom JSON, which in case of displaying a link would typically be in a UIViewController

Implementing custom JSON handeling in a UIViewController

 

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@interface SomeViewController ()
 
@property (nonatomic, weak) UIWebView *myWebView;
 
@end
 
@implementation SomeViewController
 
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // register to in-app notification system
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getLastPushNotification) name:@"PushAppsNewPushReceivedNotification" object:nil];
}
 
- (void)getLastPushNotification
{
     
    NSDictionary *customJson = [PushAppsCustomJsonManager loadLastCustomJsonMsgReceived];
    NSString *fullURL = customJson[@"last_goal_link"];
    
    if ([fullURL length] > 0) {
         
        NSURL *url = [NSURL URLWithString:fullURL];
         
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
        [self.myWebview loadRequest:requestObj];
          
    }
}
 
#define LAST_CUSTOM_JSON_KEY @"my.last.custom.json"
- (NSDictionary *)loadLastCustomJsonMsgReceived
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:LAST_CUSTOM_JSON_KEY];
}

 

 

 

Push Token

This method is being called right after receiving a push token from Apple. The method is called after the PushApps server was updated with this push token. You can use this method in order to save the token also in your server.

- (void)pushApps:(PushAppsManager *)manager didUpdateUserToken:(NSString *)pushToken

TypeNameDescription
PushAppsManager

manager

The PushAppsManager instance.
NSString

pushToken

A NSString represent the push token received from Apple.

Example:

 

1
2
3
4
5
- (void)pushApps:(PushAppsManager *)manager didUpdateUserToken:(NSString *)pushToken
{
    // This method is being called every time a push token is received from Apple (even if it did not changed from last time we asked)
}

 

Push Registration Failed

This method is being called when ever PushAppsManager was notified that an error occurred during Push Notification setup.

- (void)pushApps:(PushAppsManager *)manager registrationForRemoteNotificationFailedWithError:(NSError *)error;

TypeNameDescription
PushAppsManager

manager

The PushAppsManager instance.
NSError

error

A NSError which represent an Error.

Example:

 

1
2
3
4
5
6
7
8
9
10

- (void)pushApps:(PushAppsManager *)manager registrationForRemoteNotificationFailedWithError:(NSError *)error

{

    NSLog(@"%@", [error description]);   

    if ([[PushAppsManager sharedInstance] arePushNotificationsEnabled]) {       

        // if we failed to register, but the user approved notifications, perhaps the the app's provision profile is where the problem is.

    }

}