gpt4 book ai didi

ios - isRegisteredForRemoteNotifications 使用 semaphore_wait_trap 锁定 UI

转载 作者:行者123 更新时间:2023-11-29 11:47:13 25 4
gpt4 key购买 nike

当我的 iOS 应用程序收到推送通知时,出现了一个奇怪的情况。用户界面保持锁定状态,没有任何效果。当我暂停调试器时,我在我的线程中看到 semaphore_wait_trap

调试我能看到的代码与两件事有关:

  • 推送通知中的值类型(因为当我将 Number 更改为 String 时,问题就消失了);
  • isRegisteredForRemoteNotifications 方法(因为当我删除它时问题就消失了);

我收到如下推送通知

{aps: 
{alert: { loc-args: [Fiat, Bravo, 501],
loc-key: SOME_TEXT
},
badge: 0,
sound: default.aiff
}
}

我在 Xcode 中创建了一个新的简单项目来证明我在说什么。我正在使用以前的包标识符来接收相同的推送。按照 AppDelegate 中显示问题的代码进行操作:

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

NSLog(@"My token is: %@", deviceToken);
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
// [DefaultMethods saveInUserDefaults:@(1) forKey:kUserWasAskedForNotificationKey];
NSLog(@"Failed to get token, error: %@", error);
}

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

if( [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] ){
NSLog(@"Success");
}
}


@end

感谢您的帮助!

最佳答案

我也在处理这个问题,并且在我的设备日志中发现了这个错误:

com.apple.usernotifications.usernotificationservice: Exception caught during decoding of received message, dropping incoming message. Exception: Exception while decoding argument 0 (#2 of invocation): Exception: value for key 'NS.objects' was of unexpected class 'NSNumber'. Allowed classes are '{( NSString, NSArray )}'.

调用 isRegisteredForRemoteNotifications 后,应用程序已停止。

我们已经在我们的服务器上解决了这个问题并且问题消失了。祝你好运。

关于ios - isRegisteredForRemoteNotifications 使用 semaphore_wait_trap 锁定 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43052474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com