我正在尝试使用基于收件人时区的推送通知,但我无法让它们工作。
据我从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 +。