【问题标题】:Cordova- Push notification firebase not coming in status bar but Working in androidCordova- 推送通知 firebase 不在状态栏中,但在 android 中工作
【发布时间】:2017-08-26 00:01:53
【问题描述】:

我正在将 firebase 添加到我的 cordova 项目中。推送通知有问题,通知在运行时打印到控制台。但没有来通知栏..

关于这个的任何想法.. 我需要添加任何其他委托方法吗..

我正在获取日志 -> FCM 已连接并且当应用程序进入后台日志时 -> FCM 已断开连接

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    self.window = [[UIWindow alloc] initWithFrame:screenBounds];
    self.window.autoresizesSubviews = YES;

    // only set if not already set in subclass
    if (self.viewController == nil) {
        self.viewController = [[CDVViewController alloc] init];
    }

    // Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
    // If necessary, uncomment the line below to override it.
    // self.viewController.startPage = @"index.html";

    // NOTE: To customize the view's frame size (which defaults to full screen), override
    // [self.viewController viewWillAppear:] in your view controller.

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];




    // [self saveDeviceTokenAPI:@"83a86eb457edd131a2ace741e1214d988482dd3618f8858e1dba736e1900c733"];

    if  ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        NSLog(@"My token is......: ");

        // iOS 8 Notifications
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [application registerForRemoteNotifications];
    }
    else
    {
        NSLog(@"My token is: ");

        // iOS < 8 Notifications
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
    }




    return YES;
}

#pragma  mark :-  Push Starts here


#pragma mark- Push Notification Delegate Methods

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);

    NSString * deviceTokenString = [[[[deviceToken description]
                                      stringByReplacingOccurrencesOfString: @"<" withString: @""]
                                     stringByReplacingOccurrencesOfString: @">" withString: @""]
                                    stringByReplacingOccurrencesOfString: @" " withString: @""];

    NSLog(@"the generated device token string is : %@",deviceTokenString);

  //  [self saveDeviceTokenAPI:deviceTokenString];

    [[NSUserDefaults standardUserDefaults]setObject:deviceTokenString forKey:@"deviceToken"];

    NSLog(@"the generated device token from User defaluts : %@",[[NSUserDefaults standardUserDefaults]objectForKey:@"deviceToken"]);

}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}


#pragma  mark  for Push End here


// this happens while we are running ( in the background, or from within our own app )
// only valid if 40x-Info.plist specifies a protocol to handle
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
    if (!url) {
        return NO;
    }

    // all plugins will get the notification, and their handlers will be called
    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];

    return YES;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
#else
- (UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
#endif
{
    // iPhone doesn't support upside down by default, while the iPad does.  Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
    NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);

    return supportedInterfaceOrientations;
}

【问题讨论】:

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


    【解决方案1】:

    试试这个功能:

    - (void)launchRemoteNotificationInForegroundWithUserInfo:(NSDictionary *)userInfo {
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.fireDate = [NSDate date];
        notification.timeZone = [NSTimeZone localTimeZone];
        notification.repeatInterval = 0;
        notification.alertTitle = userInfo[@"aps"][@"alert"][@"body"];
        notification.alertBody = userInfo[@"aps"][@"alert"][@"title"];
        notification.applicationIconBadgeNumber = 1;
        notification.soundName = UILocalNotificationDefaultSoundName;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
    
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:userInfo[@"aps"][@"alert"][@"title"]
                                  message:userInfo[@"aps"][@"alert"][@"body"]
                                  delegate:self
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
    
        [alertView show];
    }
    

    并在里面调用它

    didReceiveRemoteNotification:
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多