- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我刚刚升级了为 iOS 10 注册的整个 iOS 推送通知,使用以下代码:
-(void)registerForNotifications{
if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
dispatch_async(dispatch_get_main_queue(), ^(void){
if(!error){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
});
}];
}
else {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}
我的所有委托(delegate)都在我的 AppDelegate 中设置。
编辑:我现在能够进一步确定问题所在。当应用在通知推送后返回前台时,代理:
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
仅在大约 10-15 秒后被调用,而通常它显然会立即被调用。这怎么可能?
我现在正在使用 Localytics 测试推送通知并实现:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
在我的 AppDelegate 中用于深度链接目的。当我添加断点时,我看到发生了这种情况:我正确收到推送通知,点击它,应用程序 UI 卡住了大约 10 秒。最后,didReceiveNotificationResponse 被调用,深层链接开始工作。
我怎样才能避免这种卡住应用程序的巨大延迟?
编辑:它比我还糟糕。当我将我的 iPhone 连接到 xCode 并在我的手机上运行构建时,它会在工作前卡住十秒钟。然后,如果我只是运行完全相同的构建而不在 xCode 上运行它(因此没有断点),应用程序会卡住 10 秒然后崩溃。
最佳答案
您的堆栈跟踪中有些奇怪的东西。 semaphore_wait_trap、semaphore_wait_slow。尝试查看 here和 here和 here .话虽这么说,我的猜测是您从错误的线程调用您的(void)registerForNotifications
并导致此问题。
此外,我不明白为什么您的实现中有 dispatch_async(dispatch_get_main_queue
。似乎 没有必要。尝试查看来自 here 的答案
关于iOS10 - userNotificationCenter didReceiveNotificationResponse 调用延迟 10 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42951136/
这是我的代码的一部分。我想使用 UNUserNotificationCenter 和 UNUserNotificationCenterDelegate 来处理通知事件。 当应用程序处于前台状态时,此代
这个错误刚刚开始弹出。是错误还是更新? Conflicting parameter types in implementation of 'userNotificationCenter:didRece
我正在尝试从 userNotificationCenter(_:didReceive:withCompletionHandler:) 中检索原始通知内容在 watchOS 中。从 APNS 发送推送通
我目前正在实现推送通知,我想知道 userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: 中的 com
如何读取“magazin”的值? func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response
当应用关闭且用户点击通知时: 1) 使用 remoteNotification 对象调用 didFinishLaunchingWithOptions。我按预期在此处设置了 rootViewContro
我已成功为我的消息传递应用程序设置了远程通知,并希望合并 iOS 的“快速回复”功能,现在更广为人知的是 UNUserNotificationCenter 的 UNTextInputNotificat
我正在尝试将时间值作为字符串接收,然后让通知使用该值作为触发器来显示。我的问题是通知采用这种格式来设置它的时间: var dateComponents = DateComponents()
我刚刚升级了为 iOS 10 注册的整个 iOS 推送通知,使用以下代码: -(void)registerForNotifications{ if(SYSTEM_VERSION_GRATERTHAN_
我想弄清楚我是否可以通过本地通知来实现我的目标,或者我是否需要切换到远程通知。 我正在通过构建一个闹钟程序来练习 iOS 10/Swift 3,该程序会在一天中的固定时间播放 RSS 更新的广播节目的
我有一个现有的项目,我们在其中使用 NSNotificationCenter 构建了它。现在,如果我想向我的应用程序添加丰富的通知,是否应该将所有 NSNotification 调用都替换为 NSUs
我是一名优秀的程序员,十分优秀!