5

मैं आईओएस/एंड्रॉइड में ऐप बना रहा हूं। डिवाइस में रिमोट अधिसूचना प्राप्त होने पर, didReceiveRemoteNotification कॉल किया जाना चाहिए। लेकिन यह नहीं हो रहा है। APNS के माध्यम से संदेश भेजने के लिए मेरे सर्वर साइड कोड निम्नानुसार है:didReceiveRemoteNotification नहीं आ रहा है

$deviceToken = $obj_listener->ref_id; 

// Put your private key's passphrase here: 
$passphrase = 'blahblah'; 
$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', '/var/www/mobileapp/TestAppCK.pem'); 
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 

// Open a connection to the APNS server 
$fp = stream_socket_client(
          'ssl://gateway.sandbox.push.apple.com:2195', $err, 
          $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 
if (!$fp){ 
    $this->log->debug("Failed to connect: $err $errstr" . PHP_EOL); 
    exit("Failed to connect: $err $errstr" . PHP_EOL); 
} 

$badge_count = $obj_listener->badge_count + 1; 

// Create the payload body 
$body['aps'] = array(     
        //'alert' => 'Message received', 
        'sound' => 'default', 
        'badge' => $badge_count, 
        'msg_id' => $this->msg_id, 
        //'user_key' => $obj_listener->ref_id, 
        'email' => $obj_listener->to_email_id 
       ); 

// Encode the payload as JSON 
$payload = json_encode($body); 

// Build the binary notification 
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; 

// Send it to the server 
$result = fwrite($fp, $msg, strlen($msg)); 

// Close the connection to the server 
fclose($fp); 

मेरे उद्देश्य-सी साइड कोड निम्नानुसार है:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ 

    //UIWebView *NewWebView = NULL; 
    NSLog(@"didReceiveRemoteNotification function"); 

    return; 
} 

मैं सर्वर साइड कोड में डिवाइस टोकन के लिए जाँच की है। यह डिवाइस के लिए सही है। उपर्युक्त फ़ंक्शन क्यों नहीं बुलाया जा रहा है। अग्रिम में धन्यवाद।

+1

यदि आपके आवेदन के लिए पुश अधिसूचना चालू है, तो आईफोन सेटिंग्स जांचें –

+0

इसके अलावा, सुनिश्चित करें कि आप सही प्रावधान प्रोफ़ाइल (प्रमाणपत्र से जुड़े हुए हैं जो आपने सर्वर कोड में उपयोग किया होगा।) –

+0

पर नहीं है सभी डिवाइस तक पहुंच रहे हैं। – clint

उत्तर

0

तो आवेदन पृष्ठभूमि में नहीं है आप कोड

//-------------- check notification when app is come to foreground after apllication get terminated ----------------// 

UILocalNotification *localNotif = 

[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 

if (localNotif) { 

    [self handleRemotNotification:[launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]]; // private method 


} 
1

आप अपने अनुप्रयोग शुरू में सूचनाओं के लिए रजिस्टर नहीं है, तो वे प्राप्त नहीं की जाएगी, निम्नलिखित का उपयोग करना चाहिए।

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)]; 

अब, अपने सर्वर साइड के बारे में, मैं सुझाव है कि आप डिबग मोड में अपने कोड को चलाने और देखें कि क्या एप्पल के प्रवेश द्वार ठीक से एसएसएल के माध्यम से पहुंच गया जा रहा है। एक साधारण बुरा प्रमाण या इसकी कमी आपको काम के दिन दूर ले जा सकती है। निजी अनुभव।

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