简体   繁体   中英

Method to handle errors sending push-notification

I m making an iOS notification service. But my device dont receive anything, i just take one tutorial from internet and make it.

I send more than 1 notification at time, maybe its this the problem? I have my app properly implemented (i can see it in settings).

The correct question for me is... Are there some methods you can use to see if there is any code to handle errors in sending the notifications?

Thank you.

In the Apple Documentation , look at :

Table 5-1 Codes in error-response packet

You will find what you search.

Hi There are few methods in pushnotification whice are as below

First register your device by

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

Then use its delegate methods

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken 
{
NSLog(@"Before --- Token === %@",devToken);

NSString *strServerResponse = [[[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]copy];
NSLog(@"%@",strServerResponse);

NSString * encodedURL = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)strServerResponse,NULL,(CFStringRef)@" ",kCFStringEncodingUTF8 );

NSString *DeviceToken=[Constant getUserDefaultValueForKey:@"DeviceToken"];
if([Constant checkStringNull:DeviceToken])
{
    [Constant setUserDefaultValue:encodedURL forKey:@"DeviceToken"];
}
NSLog(@"After Encoding --- Token === %@",encodedURL);
}


- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err 
{

NSLog(@"Error in registration. Error: %@", err);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"userInfo %@",userInfo);
[UIApplication sharedApplication].networkActivityIndicatorVisible=TRUE;

NSLog(@"\n\nData Received From Push Notification ===== %@",[userInfo description]);
[[UIApplication sharedApplication]setApplicationIconBadgeNumber:0 ];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM