处理发送推送通知的错误的方法

时间:2011-06-27 09:00:16

标签: iphone ios push-notification apple-push-notifications sendmessage

我正在制作iOS通知服务。但我的设备没有收到任何东西,我只是从互联网上获取一个教程并制作它。

我一次发送超过1个通知,也许这是问题所在?我已正确实施我的应用程序(我可以在设置中看到它)。

对我来说,正确的问题是......是否有一些方法可以用来查看是否有任何代码来处理发送通知时的错误?

谢谢。

2 个答案:

答案 0 :(得分:3)

Apple Documentation中,请查看:

  

表5-1错误响应中的代码   包

你会找到你搜索的内容。

答案 1 :(得分:0)

嗨推送通知中的方法很少,如下所示

首先通过

注册您的设备
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

然后使用其委托方法

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

}