0

私は Sinch SDK を正常に統合し、アプリが開いているときにうまく機能し、アプリがオフラインのときに呼び出しを処理しています。

以下の方法を使用してプッシュペアを確認でき、このプッシュペアをサーバーに送信してプッシュを配信しています。

- (void)call:(id<SINCall>)call shouldSendPushNotifications:(NSArray *) pushPairs {

}

Appdelegate.m didFinishLaunchingWithOptions () メソッドで、sinch 固有のペイロードを取得しています。

 NSDictionary* remotePush = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    NSLog(@"%@",remotePush);
    if (remotePush) {
        NSLog(@"Entery ****");
        // Extract the Sinch-specific payload from the Apple Remote Push Notification
        NSString* payload = [[remotePush valueForKey:@"aps"] valueForKey:@"SIN"];

    //    [[userInfo valueForKey:@"aps"] valueForKey:@"content-available"];
        NSLog(@"Payload :%@",payload);
        // Get previously initiated Sinch client
        id<SINClient> client = _client;
        NSLog(@"Client ID %@",[client userId]);
        id<SINNotificationResult> result = [client relayRemotePushNotificationPayload:payload];
        NSLog(@"Result :%@",result);
        if (result.isCall && result.callResult.isTimedOut) {
            // Present alert notifying about missed call
        } else if (!result.isValid) {
            // Handle error
        }
    }

完全なプッシュ通知データは次のとおりです。

{
        aps =     {
            SIN = "AgEBdeibxmJBSK2Y7Nh/fz50VMhVBVQMKzkxODg0NzE4MjQx";
            alert = "";
            "content-available" = 1;
            type = 2;
        };
    }

このコードに来る:

// Get previously initiated Sinch client
    id<SINClient> client = _client;
    NSLog(@"Client ID %@",[client userId]);

クライアントIDを印刷すると、それはNilです。以前に開始されたSinchクライアントを取得するにはどうすればよいですか? アプリが閉じているため、クライアント インスタンスは解放されます。

4

1 に答える 1

4

ユーザー ID を自分で永続化する必要があります。その後、アプリを再起動するときに、アプリをSinchClient最後に閉じたときに永続化したユーザー ID で を初期化します。

最も簡単なのはNSUserDefaults、ユーザーがログインしたときに書き込んだフィールド「userId」を使用して保存し、ユーザーがアプリからログアウトしたときに削除することです。

たとえば、起動時:

[[NSUserDefaults standardUserDefaults] setObject:userId forKey:@"userId"];

そして、APN 経由でアプリを起動すると、次のようになります。

NSString *persistedUserId = [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
if (persistedUserId != nil) {
  _client = [Sinch clientWithApplicationKey:APPLICATION_KEY
                          applicationSecret:APPLICATION_SECRET
                            environmentHost:ENVIRONMENT
                                     userId:persistedUserId];
}
于 2014-09-02T06:54:29.140 に答える