简体   繁体   English

处理推送通知错误的方法

[英]Method to handle errors sending push-notification

I m making an iOS notification service. 我在做iOS通知服务。 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 : Apple文档中 ,查看:

Table 5-1 Codes in error-response packet 表5-1差错响应报文中的编码

You will find what you search. 您将找到您要搜索的内容。

Hi There are few methods in pushnotification whice are as below 嗨,pushnotification中的方法很少,如下所示

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 ];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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