5

मेरी प्रोजेक्ट फ़ायरबेस नोटिफिकेशन को अपनी एपीएन सेवा के रूप में उपयोग करता है, लेकिन मैं अपने डिवाइस पर नोटिफिकेशन भेजने के लिए फायरबेस कंसोल का उपयोग कर रहा हूं, और वे केवल अग्रभूमि में (कंसोल आउटपुट के माध्यम से) दिखाते हैं। जब ऐप पृष्ठभूमि में होता है या डिवाइस लॉक स्क्रीन में होता है, तो डिवाइस पर कोई सूचना नहीं आती है। कंसोल आउटपुट, हालांकि, जब मैं ऐप बैक अप खोलता हूं तो आखिरकार एप्लिकेशन रीसेड रीमोट मैसेज विधि से आता है।applicationReceivedRemoteMessage केवल अग्रभूमि में निष्पादित करता है

func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { 

     print("%@", remoteMessage.appData) 
     print("QQQQQ") 
    } 

उदाहरण आउटपुट:

%@ [AnyHashable("notification"): { 
    body = Hi; 
    e = 1; 
}, AnyHashable("from"): 492525072004, AnyHashable("collapse_key"): org.myApp] 
QQQQQ 
+0

संभावित डुप्लिकेट [ऐप से बाहर होने पर एपीएन प्राप्त नहीं करना] (http://stackoverflow.com/questions/40295475/not-receiving-apns-when-out-of-app) – Chris

+0

प्रश्न जो आपने मुझे संदर्भित किया कोई जवाब नहीं है और अलग-अलग वाक्यांश है। –

उत्तर

0

iOS और डेटा संदेश के साथ कोई समस्या है। इसमें कहा गया है कि here

iOS पर, FCM संदेश संग्रहीत करता है और यह बचाता है केवल जब एप्लिकेशन को अग्रभूमि में है और एक FCM कनेक्शन स्थापित किया।

तो वहां एक काम होना चाहिए। कुछ मेरा के समान:

संदेश 2 पुश नोटिफिकेशन:

1) सामान्य उपयोगकर्ताओं को जगाने के लिए फोन/आरंभ एप्लिकेशन इस कोड का उपयोग पृष्ठभूमि में है:

{ 
    "to" : "/topics/yourTopicName", 
    "notification" : { 
    "priority" : "Normal", 
    "body" : "Notification Body like: Hey! There something new in the app!", 
    "title" : "Your App Title (for example)", 
    "sound" : "Default", 
    "icon" : "thisIsOptional" 
    } 
} 

2) डेटा अधिसूचना जो उपयोगकर्ता को ऐप खोलने पर ट्रिगर करेगी

{ 
    "to" : "/topics/yourTopicName", 
    "data" : { 
     "yourData" : "1", 
     "someMoreOfYourData" : "This is somehow the only workaround I've come up with." 
    } 
} 

और, इसलिए, - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage विधि के तहत अपने डेटा को संभाल:,

- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage { 
// Print full message 
NSLog(@"%@", remoteMessage.appData); 
// 
//*** ABOUT remoteMessage.appData ***// 
// remoteMessage.appData is a Key:Value dictionary 
// (data you sent with second/data notification) 
// so it's up to you what will it be and how will the 
// app respond when it comes to foreground. 
} 

मैं भी (स्थानीय सूचना बनाएं) ऐप्लिकेशन के अंदर सूचना उत्प्रेरित करने के लिए इस कोड को छोड़ देंगे क्योंकि आप इसका इस्तेमाल एक बना सकते हैं खामोश बैनर, हो सकता है, तो उपयोगकर्ता फिर से अधिसूचित हो जाता है तब भी जब एप्लिकेशन को अग्रभाग में आता है:

NSDictionary *userInfo = remoteMessage.appData;  
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
localNotification.userInfo = userInfo; 
localNotification.soundName = UILocalNotificationDefaultSoundName; 
localNotification.alertBody = userInfo[@"yourBodyKey"]; 
localNotification.alertTitle = userInfo[@"yourTitleKey"]; 
localNotification.fireDate = [NSDate date]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

यह अधिसूचना एक ही दूसरे एप्लिकेशन को अग्रभूमि में आता है ट्रिगर किया जाएगा।

संबंधित मुद्दे