Ios 无法使推送通知生效

Ios 无法使推送通知生效,ios,objective-c,firebase,apple-push-notifications,Ios,Objective C,Firebase,Apple Push Notifications,我正在尝试在我的应用程序中实现推送通知。我正在使用APNs身份验证密钥。到目前为止,我找到的每一本指南都有不推荐的方法,或者是Swift中的方法。我对一个像C这样的导游感兴趣 到目前为止,我在AppDelegate.m中所做的工作: @import Firebase; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

我正在尝试在我的应用程序中实现推送通知。我正在使用APNs身份验证密钥。到目前为止,我找到的每一本指南都有不推荐的方法,或者是Swift中的方法。我对一个像C这样的导游感兴趣

到目前为止,我在AppDelegate.m中所做的工作:

@import Firebase;

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

    [FIRApp configure];

    NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (userInfo) {
        [self application:application didReceiveRemoteNotification:userInfo];
    }

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

    return YES;
}


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



    // Perform different operations depending on the scenario
    if (application.applicationState == UIApplicationStateInactive) {

        // Opening the app
        NSLog(@"Firebase opening app");


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

        // Coming from background
        NSLog(@"Firebase background");

    }
    else {

        // Active
        NSLog(@"Firebase active");
    }

}
不幸的是,当我从firebase发送消息时,我什么也没有得到,在xcode控制台中没有输出,也没有通知。
如果您能为我指出正确的方向,我将不胜感激。

请使用以下方法:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
//Do something
}
与此相反:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
 //Do something
}
更新:

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

    [FIRApp configure];

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

 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
      {
        #ifdef __IPHONE_8_0
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert
                                                                                             | UIUserNotificationTypeBadge
                                                                                             | UIUserNotificationTypeSound) categories:nil];
        [application registerUserNotificationSettings:settings];
        #endif
       }
    else
      {
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
      }
    return YES;
}




-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{

    [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox];
}

您没有实现firebase apn令牌,也没有连接到数据库。为什么不像这里这样实施呢。
你有没有设置plist和POD libs?在上面的代码示例中,版本8/9的iOS部分只有不推荐的代码,这意味着您可以忽略这些代码行

没有发生任何事情。如果您使用<代码>didRegisterForRemoteNotificationsWithDeviceToken方法,我应该在哪里以及如何使用此方法?你有什么参考资料吗?我已经更新了答案,看看!如果你的问题解决了,请告诉我。嘿,谢谢你抽出时间。我使用了github的代码,它工作得非常好。这正是我所需要的。谢谢你的欢迎。我在我的上一个项目中实现了自己,它100%有效。顺便说一句,不要忘记在firebase中上传证书(仅适用于iOS,Android不需要它)。我仍然像你一样在Objective-C上-喜欢它!格里茨