来自Firebase的基于时区的推送通知无法正常工作

时间:2016-12-13 12:06:10

标签: ios objective-c firebase apple-push-notifications

我正在尝试使用基于收件人时区的推送通知,但我无法让它们工作。

据我从Firebase的某些人了解,它们会在iOS上作为数据通知发送,然后安排为本地通知。

目前,我有这段代码:

//
//  AppDelegate.h
//

@import Firebase;

@interface AppDelegate : UIResponder <UIApplicationDelegate, FIRMessagingDelegate>

@end
//
//  AppDelegate.m
//

@import UserNotifications;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {

    [FIRAnalytics handleOpenURL:url];

    return YES;
}

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

    [FIRApp configure];

    if ([UNUserNotificationCenter class]) {
        [FIRMessaging messaging].remoteMessageDelegate = self;
    }

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFirebaseTokenRefresh:) name:kFIRInstanceIDTokenRefreshNotification object:nil];

    // ...

    return YES;
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {

    [FIRAnalytics handleUserActivity:userActivity];

    return YES;
}

- (void)applicationDidEnterBackground:(UIApplication *)application {

    [[FIRMessaging messaging] disconnect];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {

    [self connectToFirebase];
}

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

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

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

    [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
}

- (void)onFirebaseTokenRefresh:(NSNotification *)notification {

    [self connectToFirebase];
}

- (void)connectToFirebase {

    NSString *firebaseToken = [[FIRInstanceID instanceID] token];

    if (!firebaseToken) {
        return;
    }

    FIRMessaging *firebaseMessaging = [FIRMessaging messaging];

    [firebaseMessaging disconnect];

    [firebaseMessaging connectWithCompletion:^(NSError *error) {
        if (error != nil) {
            return;
        }

        NSTimeInterval updatedAt = floor([NSDate date].timeIntervalSince1970);

        [FIRAnalytics setUserPropertyString:@(updatedAt).stringValue forName:@"UpdatedAt"];
    }];
}

#pragma mark - FIRMessagingDelegate

- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {}

@end

我也有残疾人士。

我也有application:didReceiveRemoteNotification:fetchCompletionHandler:,因为我必须支持iOS 7 +。

  1. 我应该手动安排本地通知,还是Firebase SDK会这样做?
  2. 这些“数据通知”是否与iOS 7 +兼容?
  3. 我应该在“applicationReceivedRemoteMessage:”委托方法中做些什么?
  4. 是否有必要为预定的时区通知启用任何后台模式功能?

0 个答案:

没有答案