OGeek|极客世界-中国程序员成长平台

标题: ios - 当应用程序终止并且手机被锁定时,VOIP Push 代表不会被调用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:07
标题: ios - 当应用程序终止并且手机被锁定时,VOIP Push 代表不会被调用

我正在处理 VOIP 应用程序,当应用程序处于前台或后台时,我也收到了 voip 推送,但是当应用程序终止或强制退出时 并且 iPhone 进入了锁定模式……设备获取 voip 推送(我在设备控制台中检查了)

Received message for enabled topic 'com.kipl.app.voip' with payload '{
    aps =     {
        alert = "Misscall from +91 9782260101";
        "content-available" = 1;
        sound = default;
    };
    "message_data" =     {
        UUID = "E740A875-65B2-4E4C-AF3C-3B886AA040F3";
        handle = 919782260101;
        hasVideo = 0;
        image = "201702/589c6c27febed30d03c32f54.jpg";
        message = "Misscall from +91 9782260101";
        phone = "+91 9782260101";
        pushType = miscall;
        username = "";
    };
}' onInterface: NonCellular  for device token: NO  with priority (null)
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSMessageStore: 0x10035adb0> asked to store incoming message <APSIncomingMessage: 0x1003a1f00> with guid B0C02302-772D-423B-A525-A0115F98DA29 environment <APSEnvironment: 0x10030f610: production>
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSCourier: 0x100311180>: Calling into AWD for PushReceived
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSCourier: 0x100311180>: AWD for PushReceived finished
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSCourier: 0x100311180>: Stream processing: complete no, invalid no, length parsed 0, parameters (null)
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: APSMessageStore - New message record [<APSIncomingMessageRecord 0x1004d7540 [0x1ac0d6bb8]>{}] has ID [1400].
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSMessageStore: 0x10035adb0> calling completion block for incoming message B0C02302-772D-423B-A525-A0115F98DA29
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSCourier: 0x100311180>: Sending acknowledgement message with response 0 and messageId <04000000> (4)
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSCourier: 0x100311180> Noting push - using last lq 0 and rat (null)  (instead of -2, kCTRegistrationRadioAccessTechnologyUnknown)
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSDecayTimer: 0x1004127f0>:APSNetworkMonitor decaying cost (381 - 6) = 375 for 24.425812 seconds
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSDecayTimer: 0x1004127f0>:APSNetworkMonitor addCost: 166 - _currentCost is now 541
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: <APSCourier: 0x100311180> _notifyForIncomingMessage <APSIncomingMessage: 0x1003a1f00> with guid B0C02302-772D-423B-A525-A0115F98DA29
Mar  4 12:52:14 iPhone apsd(PersistentConnection)[86] <Notice>: 2017-03-04 12:52:14 +0530 apsd[86]: Dispatching high priority message: <OS_xpc_dictionary: <dictionary: 0x1003ed2a0> { count = 2, transaction: 0, voucher = 0x0, contents =
    "message" => <dictionary: 0x10038a050> { count = 1, transaction: 0, voucher = 0x0, contents =
        "ECF19A18-7AA6-4141-B4DC-A2E5123B2B5C" => <data: 0x1003a8360>: { length = 16384 bytes, contents = 0x62706c6973743135137e020000000000801200000000d87f... }
    }
    "message-type" => <int64: 0x10035c950>: 30
}>

也调用了 didFinishLaunchingWithOptionspushkit 委托(delegate)没有调用。我也正在使用调用套件来接听电话。

1) 当应用在前台时...推送工作

2) 应用程序从后台移除并锁定手机...在设备中推送接收但 pushkit 委托(delegate)未调用.. 问题

谁能提出建议,我该如何解决这个问题?



Best Answer-推荐答案


您也可以逐步引用整个pushkit流程。

Swift 和 Objective C 代码也在那里。

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

AppDelegate中的pushkit委托(delegate)请引用以下代码。

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {


    pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
    pushRegistry.delegate = self;
    pushRegistry.desiredPushTypes = [NSSet setWithObjectKPushTypeVoIP];

    return YES;
}

#define PushKit Delegate Methods

- (void)pushRegistryPKPushRegistry *)registry didUpdatePushCredentialsPKPushCredentials *)credentials forTypeNSString *)type{
    if([credentials.token length] == 0) {
        NSLog(@"voip token NULL");
        return;
    }

    NSLog(@"ushCredentials: %@", credentials.token);
}

- (void)pushRegistryPKPushRegistry *)registry didReceiveIncomingPushWithPayloadPKPushPayload *)payload forTypeNSString *)type
{
    NSLog(@"didReceiveIncomingPushWithPayload");
}

- (void)applicationWillResignActiveUIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackgroundUIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

希望这会对你有所帮助。

一切顺利。

调试处于终止状态的 pudhkit 委托(delegate)。

将调试指针放在委托(delegate)方法上,转到编辑方案,选择运行选项然后启动 -> 等待启动可执行文件。从后端发送推送工具包负载,一旦您在设备上获取负载,它将自动调用,调试指针将在委托(delegate)方法处调用。

enter image description here

关于ios - 当应用程序终止并且手机被锁定时,VOIP Push 代表不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42524501/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4