0

私はiOSプログラマではありません。プッシュ通知を受け取ることはできますが、画面には2つのアラートが表示されます。IOS通知がデフォルトで2回表示され、通知通知が表示されます

問題1:私は の下に作成していUIAlertView* alertWindow -One - 第二には、デフォルトの通知アラートウィンドウのようです。 2番目のウィンドウを作成するときに間違っていることは何ですか?

問題2:デバイスがロックされていると、画面に通知が表示されますが、これはデフォルトの通知ウィンドウです。私はdidReceiveRemoteNotificationに入っている詳細の通知は表示されません。

if elseブロックについて誰かがdidFinishLaunchingWithOptionsで説明できることをお詫び申し上げます。私はそれを貼り付けた。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    NSString *AMAZON_SERVER = @"xxxxxx"; 

    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | 
               UIUserNotificationTypeBadge | 
               UIUserNotificationTypeSound); 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes 
                     categories:nil]; 
    [application registerUserNotificationSettings:settings]; 
    [application registerForRemoteNotifications]; 

    [Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) { 
     configuration.applicationId = APPLICATION_ID; 
     configuration.clientKey = CLIENT_KEY; 
     configuration.server = AMAZON_SERVER; 
    }]]; 

    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions]; 

    [Fabric with:@[[Digits class]]]; 

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) 
    { 
     [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 

    } 
    else 
    { 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; 
    } 

    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 

    [application registerUserNotificationSettings:settings]; 
    [application registerForRemoteNotifications]; 

    if([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"]!=TRUE) 
    { 
     [[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:@"FirstLaunch"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 
    } 
    //storedevice Type in standardUserDefaults 
    [self setDeviceType]; 
    return YES; 
} 

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { 
    [application registerForRemoteNotifications]; 
} 

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    // Store the deviceToken in the current installation and save it to Parse. 
    PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
    [currentInstallation setDeviceTokenFromData:deviceToken]; 
    [currentInstallation saveInBackground]; 
} 

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    NSLog(@"Error in registration. Error: %@", err); 
} 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    [PFPush handlePush:userInfo]; 
    if ([userInfo objectForKey:@"aps"]) { 
     NSMutableDictionary * apsData = [userInfo objectForKey:@"aps"]; 
     NSString* alert = [apsData objectForKey:@"alert"]; 
    ... 
    ... 

     UIAlertView* alertWindow = [[UIAlertView alloc] initWithTitle: alertHeader 
                message: message 
                delegate: self 
              cancelButtonTitle: @"OK" 
              otherButtonTitles: nil]; 

     [alertWindow show]; 
     AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 
    } else { 
     [PFPush handlePush:userInfo]; 
    } 
} 
+0

あなたは2回登録されています。問題が発生します –

+0

それがアクティブであればそれを表示し、それ以外の場合はアラートを表示しないでください。 Active状態の通知バナーは表示されないためです。 –

+0

@ HariKrishnan.P 2回登録した場所を教えてください。あなたは 'didReceiveRemoteNotification' – user1324887

答えて

1
First uninstall the app and try it. It will work fine same problem i am facing. 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 


    [Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) { 
     configuration.applicationId = APPLICATION_ID; 
     configuration.clientKey = CLIENT_KEY; 
     configuration.server = AMAZON_SERVER; 
    }]]; 

    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions]; 

    [Fabric with:@[[Digits class]]]; 



    if([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"]!=TRUE) 
    { 
     [[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:@"FirstLaunch"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 
    } 
    //storedevice Type in standardUserDefaults 
    [self setDeviceType]; 
     #here i am edited 

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) 
    { 


    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
    [[UIApplication sharedApplication] registerForRemoteNotifications]; 

} 
else 
{ 

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
    (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; 


} 



    return YES; 
} 
// remove the below methods 

    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { 
    [application registerForRemoteNotifications]; 
} 

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    // Store the deviceToken in the current installation and save it to Parse. 
    PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
    [currentInstallation setDeviceTokenFromData:deviceToken]; 
    [currentInstallation saveInBackground]; 
} 

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    NSLog(@"Error in registration. Error: %@", err); 
} 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    //[PFPush handlePush:userInfo]; 
    if ([userInfo objectForKey:@"aps"]) { 
     NSMutableDictionary * apsData = [userInfo objectForKey:@"aps"]; 
     NSString* alert = [apsData objectForKey:@"alert"]; 
    ... 
    ... 

     UIAlertView* alertWindow = [[UIAlertView alloc] initWithTitle: alertHeader 
                message: message 
                delegate: self 
              cancelButtonTitle: @"OK" 
              otherButtonTitles: nil]; 

     [alertWindow show]; 
     AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 
    } else { 
     [PFPush handlePush:userInfo]; 
    } 
} 
0

あなたのif文は、あなたの[UIApplication sharedApplication]インスタンスがregisterUserNotificationSettings:メソッドを実装している場合、ブロックは、それ以外の場合は、他のブロックを実行する場合は、それが実行されることを言います。

関連する問題