2016-08-25 16 views
0

通知をプッシュすると、iPhoneの画面がオンになります(おそらく、アプリが起動しているためです)。ただし、ロック画面や通知タブに通知は表示されません。画面がロックされているとApple Push Notification(リモート)が機能していません。 Appleの通知タブに何も表示されない

画面がロックされていると、iOS通知が機能していません。 [通知]タブには何も表示されません。アプリがバックグラウンド(画面のロックが解除されている)またはフォアグラウンドの場合、バナーは正常に機能しています。私は(:https://github.com/argon/node-apn/issues/418私もレポにチケットをオープンしました):ノード-APN使用して通知をプッシュするには、次のコードを使用し

function pushNotificationToMany() { 
    console.log("Sending the same notification each of the devices with one call to pushNotification."); 
    var note = new apn.notification(); 
    note.setAlertTitle("Hello from my app"); 
    note.setAlertText("Hello, world!"); 
    note.setCategory("message"); 
    note.setContentAvailable(1); 
    note.badge = 1; 

    service.pushNotification(note, tokens); 
} 

pushNotificationToMany(); 

私のiOSのコードAppDelegate.mには、以下の機能があります

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Override point for customization after application launch. 
    NSLog(@"Registering for push notifications..."); 
    UIMutableUserNotificationCategory* notificationCategory = [[UIMutableUserNotificationCategory alloc] init]; 
    notificationCategory.identifier = @"message"; 
    NSSet *categories = [NSSet setWithObjects:notificationCategory, nil]; 
    [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:categories]]; 
    NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
    if (payload) 
     NSLog(@"payload is : %@", payload); 
    return YES; 
} 
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings // NS_AVAILABLE_IOS(8_0); 
{ 
    [application registerForRemoteNotifications]; 
} 
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{ 

    NSLog(@"deviceToken: %@", deviceToken); 
    NSString * token = [NSString stringWithFormat:@"%@", deviceToken]; 
    //Format token as you need: 
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; 
    token = [token stringByReplacingOccurrencesOfString:@">" withString:@""]; 
    token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""]; 

} 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    NSLog(@"remote notification user info %@", userInfo); 
} 
- (void)application:(UIApplication *)application 
didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler { 
    NSLog(@"another remote notification user info %@", userInfo); 
    if(application.applicationState == UIApplicationStateInactive) { 

     NSLog(@"Inactive"); 

     //Show the view with the content of the push 

     handler(UIBackgroundFetchResultNewData); 

    } else if (application.applicationState == UIApplicationStateBackground) { 

     NSLog(@"Background"); 

     //Refresh the local model 

     handler(UIBackgroundFetchResultNewData); 

    } else { 

     NSLog(@"Active"); 

     //Show an in-app banner 

     handler(UIBackgroundFetchResultNewData); 

    } 
} 
+0

通知を受け取るために使用するPHPスクリプトがあります。 – vaibhav

答えて

0

私が望む結果を得るには、UIMutableUserNotificationActionを追加する必要があります。次のコードが動作します:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Override point for customization after application launch. 
    NSLog(@"Registering for push notifications..."); 

    UIMutableUserNotificationAction *notificationAction1 = [[UIMutableUserNotificationAction alloc] init]; 
    notificationAction1.identifier = @"Accept"; 
    notificationAction1.title = @"Accept"; 
    notificationAction1.activationMode = UIUserNotificationActivationModeBackground; 
    notificationAction1.destructive = NO; 
    notificationAction1.authenticationRequired = NO; 

    UIMutableUserNotificationAction *notificationAction2 = [[UIMutableUserNotificationAction alloc] init]; 
    notificationAction2.identifier = @"Reject"; 
    notificationAction2.title = @"Reject"; 
    notificationAction2.activationMode = UIUserNotificationActivationModeBackground; 
    notificationAction2.destructive = YES; 
    notificationAction2.authenticationRequired = YES; 

    UIMutableUserNotificationAction *notificationAction3 = [[UIMutableUserNotificationAction alloc] init]; 
    notificationAction3.identifier = @"Reply"; 
    notificationAction3.title = @"Reply"; 
    notificationAction3.activationMode = UIUserNotificationActivationModeForeground; 
    notificationAction3.destructive = NO; 
    notificationAction3.authenticationRequired = YES; 

    UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init]; 
    notificationCategory.identifier = @"Email"; 
    [notificationCategory setActions:@[notificationAction1,notificationAction2,notificationAction3] forContext:UIUserNotificationActionContextDefault]; 
    [notificationCategory setActions:@[notificationAction1,notificationAction2] forContext:UIUserNotificationActionContextMinimal]; 

    NSSet *categories = [NSSet setWithObjects:notificationCategory, nil]; 

    UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 
    UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:categories]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; 

    [[UIApplication sharedApplication] registerForRemoteNotifications]; 
// [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:categories]]; 
    NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
    if (payload) 
     NSLog(@"payload is : %@", payload); 
    return YES; 
} 
関連する問題