1

我正在尝试使用 pushy.me 向我的应用程序发送推送通知。当应用程序在后台时,我无法对收到的数据做任何事情,除非我点击通知横幅或应用程序在前台..

这是我的通知负载

   {
  "registration_ids": [
  "692d1e6c16d483a4613193"
   ],
   "data": {
   "title": "Test Notification",
   "message": "hello"
  },
  "notification": {
    "body": "Hello World ✌",
    "badge": 1,
    "content-available" : "1",
   "mutable-content" : "1",
    "sound": "ping.aiff"
  }
}

代码:

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

    NSLog(@"%@", pushInfo);

    if(application.applicationState == UIApplicationStateInactive) {

        NSLog(@"Inactive - the user has tapped in the notification when app was closed or in background");
        //do some tasks
      //  [self manageRemoteNotification:userInfo];
        completionHandler(UIBackgroundFetchResultNewData);
    }
    else if (application.applicationState == UIApplicationStateBackground) {
        //NOT WORKING
        NSLog(@"application Background - notification has arrived when app was in background");
        NSString* contentAvailable = [NSString stringWithFormat:@"%@", [[pushInfo valueForKey:@"aps"] valueForKey:@"content_available"]];


        if([contentAvailable isEqualToString:@"1"]) {
            // do tasks


        //    [self manageRemoteNotification:userInfo];
            NSLog(@"content-available is equal to 1");
        //    completionHandler(UIBackgroundFetchResultNewData);
        }
    }
    else {
        NSLog(@"application Active - notication has arrived while app was opened");
        //Show an in-app banner
        //do tasks
     //   [self performFetchWithCompletionHandler];
        completionHandler(UIBackgroundFetchResultNewData);
    }
}
4

0 回答 0