2017-03-10 13 views
7

मैं चैट एप पर काम कर रहा हूं जो पुश अधिसूचना प्राप्त करता है। मैं आईओएस द्वारा पुश अधिसूचना में प्रदर्शित करने के लिए छवियों/आइकन प्रदान करना चाहता हूं, मैं एक्सकोड में कहां निर्दिष्ट कर सकता हूं?आइकन?

+1

आप AFAIK नहीं कर सकते हैं। यह आपके ऐप के आइकन का उपयोग करेगा। आप यहां और अधिक पढ़ सकते हैं: https://developer.apple.com/ios/human-interface-guidelines/features/notifications/ – Losiowaty

+1

सुनिश्चित करें कि आप images.xcassets का उपयोग करके कर सकते हैं। बस "आईफोन अधिसूचना"/"आईपैड अधिसूचना" क्षेत्र में इच्छित छवि डालें –

+1

आपको इसे देखना चाहिए: http://stackoverflow.com/questions/37839171/how-to-display-image-in- आईओएस-पुश-अधिसूचना – Milander

उत्तर

0

सबसे पहले आप की जरूरत है यह पूरा आपके Info.plist फ़ाइल गोटो और चिह्न फ़ाइल है कि

<key>CFBundleIcons</key> 
    <dict> 
     <key>CFBundleAlternateIcon</key> 
     <dict> 
      <key>first_icon</key> 
      <dict> 
       <key>CFBundleIconFile</key> 
       <array> 
        <string>first_icon.png</string> 
       </array> 
      </dict> 
      <key>second_icon</key> 
      <dict> 
       <key>CFBundleIconFile</key> 
       <array> 
        <string>second_icon.png</string> 
       </array> 
      </dict> 
     </dict> 
     <key>CFBundlePrimaryIcon</key> 
     <dict> 
      <key>CFBundleIconFiles</key> 
      <array> 
       <string></string> 
      </array> 
      <key>UIPrerenderedIcon</key> 
      <false/> 
     </dict> 
     <key>UINewsstandIcon</key> 
     <dict> 
      <key>CFBundleIconFiles</key> 
      <array> 
       <string></string> 
      </array> 
      <key>UINewsstandBindingType</key> 
      <string>UINewsstandBindingTypeMagazine</string> 
      <key>UINewsstandBindingEdge</key> 
      <string>UINewsstandBindingEdgeLeft</string> 
     </dict> 
    </dict> 

अब आप अपने AppDelegate फ़ाइल में सेटिंग विन्यस्त करने की जरूरत में कुछ गुण को जोड़ने के लिए

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

     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 

     NSDictionary *notificationData = [[PushNotificationManager pushManager] getCustomPushDataAsNSDict:userInfo]; 
     NSString * notiIcon = [notificationData objectForKey:@"newIcon"]; 
     if([notiIcon isEqualToString:@"nil"]) 
      notiIcon = nil; 

     NSLog(@"icon is: %@", notiIcon); 

     [[UIApplication sharedApplication] setAlternateIconName:notiIcon completionHandler:^(NSError * _Nullable error) { 
      NSLog(@"Set icon error = %@", error.localizedDescription); 
     }]; 
     }); 

अब किसी भी डैशबोर्ड से आप ऐप को अधिसूचना भेजते हैं और Action नामक विकल्प और send Custom data जैसे कुछ key-value कोड में जोड़ी हम कुंजी 'newIcon' का उपयोग कर रहे हैं तो इसे

{"newIcon":"first_icon"} 

अब भेजें जब आप आइकन नाम के साथ अधिसूचना भेजेंगे जो दिखाई देगा।

यह काम करेगा ..

+0

@ आशीष नगर मैंने अपना जवाब बदल दिया है मेरे पिछले उत्तर को कुछ प्रतिलिपि सही मुद्दों के कारण हटा दिया गया था अब यह जांचें –