Non si può rilevare che il caso, perché l'applicazione non è aperta con notifica push (è è stato aperto tramite l'icona dell'app).
Provare ad aprire l'applicazione facendo scorrere la notifica push.
EDIT:
Se si desidera ad essere invocate per notifica push (via sfondo prendere, quando l'applicazione non è attiva) è necessario chiedere il vostro sviluppatore di back-end per impostare "content-available": 1
nella notifica push.
Dopo che -application:didReceiveRemoteNotification:fetchCompletionHandler:
verrà richiamato (quando la notifica push-arriva), in modo da poter salvare il payload in un file e poi quando l'applicazione sarà aperto, è possibile leggere il file e prendere azioni.
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(@"#BACKGROUND FETCH CALLED: %@", userInfo);
// When we get a push, just writing it to file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"userInfo.plist"];
[userInfo writeToFile:filePath atomically:YES];
completionHandler(UIBackgroundFetchResultNewData);
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Checking if application was launched by tapping icon, or push notification
if (!launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"userInfo.plist"];
[[NSFileManager defaultManager] removeItemAtPath:filePath
error:nil];
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:filePath];
if (info) {
// Launched by tapping icon
// ... your handling here
}
} else {
NSDictionary *info = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
// Launched with swiping
// ... your handling here
}
return YES;
}
Inoltre, non dimenticare di abilitare le notifiche "remote" in "Modalità di sfondo"
u può mostrare tutto il codice o in quale metodo ti sei trovato a userinfo? – Vizllx
in "- (BOOL) applicazione: (UIApplication *) didFinishLaunchingWithOptions di applicazione: (NSDictionary *) launchOptions {}" e "- (BOOL) Applicazione: (UIApplication *) willFinishLaunchingWithOptions di applicazione: (NSDictionary *) launchOptions" –