2011-12-05 7 views
0

私のアプリでプッシュ通知サービスを使用しています。プッシュ通知のレジスターに失敗したデバイスが常に表示されています

しかし、今では、(アプリ起動時に)プッシュ通知に登録できませんでした。

私は、プッシュ通知のために以下のコードを使用:

誰も私が間違って行くよどこに私を助けることができます。

ありがとうございます。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    if(application.applicationIconBadgeNumber != 0){ 
     [[[[[self tabBarController] viewControllers] objectAtIndex: 1] tabBarItem] setBadgeValue:@"new"];} 




    [self.window addSubview:tabBarController.view]; 
    [self.window makeKeyAndVisible]; 
    NSLog(@"Registering for push notifications...");  
    [[UIApplication sharedApplication] 
    registerForRemoteNotificationTypes: 
    (UIRemoteNotificationTypeAlert | 
     UIRemoteNotificationTypeBadge | 
     UIRemoteNotificationTypeSound)]; 
     return YES; 

} 


- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    NSLog(@"asdfasdf"); 

    NSString *str = [NSString 
        stringWithFormat:@"Device Token=%@",deviceToken]; 

     const char* data = [deviceToken bytes]; 
    NSMutableString* token = [NSMutableString string]; 

    for (int i = 0; i < [deviceToken length]; i++) { 
     [token appendFormat:@"%02.2hhX", data[i]]; 
    } 

    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://chargrilled.k-hosting.co.uk/test2/register_device.php?dt=%@",token]]; 
    NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url]autorelease]; 
    NSURLConnection* connection = [NSURLConnection connectionWithRequest:request delegate:self]; 


    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Device registered for push notification." 
               message:nil 
               delegate:self 
             cancelButtonTitle:nil 
             otherButtonTitles:@"Okay", nil]; 
    [alert show]; 
    [alert release]; 



} 
- (NSString*)stringWithDeviceToken:(NSData*)deviceToken { 


} 


- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Device registration failed." 
               message:nil 
               delegate:self 
             cancelButtonTitle:nil 
             otherButtonTitles:@"Okay", nil]; 
    [alert show]; 
    [alert release]; 

} 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    int i; 

    for (id key in userInfo) { 
     i++; 
     NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]); 
     if(i==2){ 

     } 
    } 

    application.applicationIconBadgeNumber = [[userInfo objectForKey:@"badge"] integerValue]; 
    [[[[[self tabBarController] viewControllers] objectAtIndex: 1] tabBarItem] setBadgeValue:@"new"]; 


} 

答えて

3

プッシュ通知を有効にするかどうかを確認してください。プッシュ通知で新規作成しない場合

+0

、はい..u r正しい。ありがとうございます.. – ishhhh

関連する問題