2016-09-16 7 views
1

Whatsapp (또는 Viber) iOS 응용 프로그램이 완전히 꺼져 있고 (배경에서 제거 된) 메시지 수신은 예상대로 푸시 알림을 통해 처리됩니다.
푸시 알림에서 Whatsapp (또는 Viber)를 깨우면 서버에서 명시 적으로 다운로드하지 않고 수신 된 모든 메시지를 즉시 표시합니다.
실제로, 모든 푸시 알림이 전송 된 메시지를 다운로드하기에 충분한 시간 동안 앱을 깨우는 것처럼 보입니다. 이는 iOS에서는 불가능합니다.
Whatsapp 또는 Viber에서 푸시 알림 인스턴트 메시지

사람들이 어떻게 메시지 묶음을 빠르게 받아 들였는가?

+0

사용 소켓 또는 xmpp 서버를 통해 구현합니다. – Monish

+0

소켓을 사용하고 있습니다. – Branko

+0

실제로 메시지를 일괄 적으로 가져 오는 메커니즘을 구현해야합니다. whatsapp에 많은 메시지를 얻었을 때 관찰하면 메시지를 일괄 적으로 가져 왔습니다. – Monish

답변

1

당신은 아마 당신의 엑스 코드 프로젝트> 기능 창에서 활성화 음성 IP를 통한 백그라운드 모드과 함께 PushKit을 사용해야합니다. 그렇게하면 VoIP 푸시 알림 기능이 응용 프로그램을 깨울 수 있으므로 수신 된 데이터를 처리하고 표시 할 수 있습니다. 또한 VoIP 푸시는 표준 푸시 알림보다 몇 가지 장점이 있습니다. 더 많은 정보는 here에서 찾을 수 있습니다.

+0

참. pushkit @ Branko를 사용하면 앞서 언급 한 아키텍처를 관리 할 수 ​​있습니다. – Hasya

0

백그라운드 모드 또는 죽이기 모드에 상관없이 앱이 백그라운드에서 호출됩니다. 귀하의 앱은 귀하의 지역 알림이 최대 30 초 동안 재생 될 때까지 활성화 될 것입니다.

구조를 사용하여 작업을 수행하십시오.

사용

<?php 

// Put your device token here (without spaces): 


     $deviceToken = '123456789'; 
// 


// Put your private key's passphrase here: 
$passphrase = 'ProjectName'; 

// Put your alert message here: 
$message = 'My first push notification!'; 



$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', 'PemFileName.pem'); 
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 

// Open a connection to the APNS server 
$fp = stream_socket_client(
// 'ssl://gateway.push.apple.com:2195', $err, 
    'ssl://gateway.sandbox.push.apple.com:2195', $err, 
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 

if (!$fp) 
    exit("Failed to connect: $err $errstr" . PHP_EOL); 

echo 'Connected to APNS' . PHP_EOL; 

// Create the payload body 

$body['aps'] = array(
        'content-available'=> 1, 
        'alert' => $message, 
        'sound' => 'default', 
        'badge' => 0, 
        ); 



// 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)); 

if (!$result) 
    echo 'Message not delivered' . PHP_EOL; 
else 
    echo 'Message successfully delivered' . PHP_EOL; 

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

사용 아래이 simplepush.php 파일 위치 및 화재 명령을 simplepush.php로 이동 PEM 파일을 생성하고 그 후 위의 코드

$ openssl x509 -in aps_development.cer -inform der -out PushCert.pem 

# Convert .p12 to .pem. Enter your pass pharse which is the same pwd that you have given while creating the .p12 certificate. PEM pass phrase also same as .p12 cert. 
$ openssl pkcs12 -nocerts -out PushKey1.pem -in pushkey.p12 

Enter Import Password: 

MAC verified OK 

Enter PEM pass phrase: 

Verifying - Enter PEM pass phrase: 

# To remove passpharse for the key to access globally. This only solved my stream_socket_client() & certificate capath warnings. 
$ openssl rsa -in PushKey1.pem -out PushKey1_Rmv.pem 

Enter pass phrase for PushChatKey1.pem: 

writing RSA key 

# To join the two .pem file into one file: 
$ cat PushCert.pem PushKey1_Rmv.pem > ApnsDev.pem 

에서 사용하는 명령 -> php simplepush.php

이렇게하면 푸시 킷 알림 설정 아키텍처를 테스트 할 수 있습니다. Download

import UIKit 
import PushKit 


class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate{ 



func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 


    let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound] 
    application.registerForRemoteNotificationTypes(types) 

    self. PushKitRegistration() 

    return true 
} 



//MARK: - PushKitRegistration 

func PushKitRegistration() 
{ 

    let mainQueue = dispatch_get_main_queue() 
    // Create a push registry object 
    if #available(iOS 8.0, *) { 

     let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue) 

     // Set the registry's delegate to self 

     voipRegistry.delegate = self 

     // Set the push type to VoIP 

     voipRegistry.desiredPushTypes = [PKPushTypeVoIP] 

    } else { 
     // Fallback on earlier versions 
    } 


} 


@available(iOS 8.0, *) 
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) { 
    // Register VoIP push token (a property of PKPushCredentials) with server 

    let hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(credentials.token.bytes), 
     count: credentials.token.length).map { String(format: "%02x", $0) }.joinWithSeparator("") 

    print(hexString) 


} 


@available(iOS 8.0, *) 
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) { 
    // Process the received push 
    // From here you have to schedule your local notification 

} 

} 

당신이 더 이상 도움이 필요하면 알려주세요

https://www.raywenderlich.com/123862/push-notifications-tutorial

. 행복한 코딩.

관련 문제