Message-ID: <2057860069.2572.1416866541768.JavaMail.javamailuser@localhost> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2571_637966099.1416866541765" ------=_Part_2571_637966099.1416866541765 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html PushApps Delegation

PushApps Delegation

PushApps gives you the ability to focus on the important and uni= que 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 cr= eated the PushApps delegate.

 

 

Icon

The methods in the PushAppsDelegate, are all optional.

Handle Notif= ications

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

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

Type Name Description
PushAppsManager

manager

The PushAppsManager instance.
NSDictionary

pushNotification

A NSDictionary, contains all the i= nformation about the push message - the "aps" object (contains th= e 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 foreg= round while receiving the message.

Example:

 

1
2
3
4
5
6
7
- ( void )pushApps:(PushAppsManager *)manager didReceiveRe= moteNotification:(NSDictionary *)pushNotification whileInForeground:( BOOL )inForeground
{
     // This method is being called on each incomin= g push message. It does not matter if the app is opened or closed, in foreg= round 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 sco= red, 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 lo= ok like this:

custom JSON

 

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

 

When the Push Notification arrives, you will get notified by the delegat= e 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 didReceiveRe= moteNotification:(NSDictionary *)pushNotification whileInForeground:( BOOL )inForeground
{
     
     // you will need to pass a pushDictionary and = the customJsonKey you have specified in the web service.
     [self extractInfoFromC= ustomJson:pushNotification withCustomJsonKey:@ "Data" ];
     
}
 
#define LAST_CUSTOM_JSON_KEY @"my.las= t.custom.json"
- ( void )extractInfoFromCustomJson:(NSDictionary *)pushDi= ctionary withCustomJsonKey:(NSString *)customJsonKey
{
     NSString *customJsonString =3D pushDictionary[cus= tomJsonKey];
     
     if=20 (customJsonString) { // if the JSON exists
        =  
        = // we will convert it to get a 'clean' NSDicti= onary
        = NSData *customJsonData =3D [customJsonString data= UsingEncoding:NSUTF8StringEncoding];
        =  
        = id json =3D [NSJSONSerialization JSONObjectWithDa= ta:customJsonData options:0 error:nil];
        =  
        = NSDictionary *customJson;
        =  
        = if=20 ([json isKindOfClass:[NSDictionary class ]]) {
        =      
        =      customJson =3D (NSDictionary *)json;
        =      
        = }
        =  
        = if=20 (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 notifica= tion.
        =      [[NSUserDefaults standardUserDefaults] setOb= ject:customJson forKey:LAST_CUSTOM_JSON_KEY];
        =      [[NSUserDefaults standardUserDefaults] synchroniz= e];
        =      
        =      [[NSNotificationCenter defaultCenter] postNotific= ationName:@ "PushAppsNewPushReceivedNotification"<= /code>=20 object:nil];
        = }
     }
}

 

Now, we should prepare an implementation for the custom JSON, which in c= ase 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] addObserve= r:self selector:@selector(getLastPushNotification) name:@ "PushAppsNewPushReceivedNotification"<= /code>=20 object:nil];
}
 
- ( void )getLastPushNotification
{
     
     NSDictionary *customJson =3D [PushAppsCustomJsonM= anager loadLastCustomJsonMsgReceived];
     NSString *fullURL =3D customJson[@ "last_goal_link" ];
    
     if=20 ([fullURL length] > 0) {
        =  
        = NSURL *url =3D [NSURL URLWithString:fullURL];
        =  
        = NSURLRequest *requestObj =3D [NSURLRequest req= uestWithURL:url];
        = [self.myWebview loadRequest:requestObj= ];
        =   
     }
}
 
#define LAST_CUSTOM_JSON_KEY @"my.las= t.custom.json"
- (NSDictionary *)loadLastCustomJsonMsgReceived
{
     return=20 [[NSUserDefaults standardUserDefaults] objectForK= ey:LAST_CUSTOM_JSON_KEY];
}

 

 

 

Push Token

This method is being called right after receiving a push token from Appl= e. The method is called after the PushApps server was updated with this pus= h token. You can use this method in order to save the token also in your se= rver.

- (void)pushApps:(PushAppsManager *)= manager didUpdateUserToken:(NSString *)pushT= oken

Type Name Description
PushAppsManager

manager

The PushAppsManager instance.
NSString

pushToken

A NSString represent the push toke= n received from Apple.

Example:

 

1
2
3
4
5
- ( void )pushApps:(PushAppsManager *)manager didUpdateUse= rToken:(NSString *)pushToken
{
     // This method is being called every time a pu= sh 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 registrationForRemoteNo= tificationFailedWithError:(NSError *)error;

Type Name Description
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 registrationForRemoteNotific= ationFailedWithError:(NSError *)error

{

    NSLog(@"%@", [error description]); &nb= sp; 

    if ([[PushAppsManager sharedInstance] arePushNotifica= tionsEnabled]) {       

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

    }

}

------=_Part_2571_637966099.1416866541765--