- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我的 ViewDidLoad 上创建了一个 Darwin 通知,我想在调用回调时调用一个 UIAlert。在这种情况下,我想在屏幕解锁时调用警报,为此我将创建一个变量,该变量将在第二次调用此回调时设置为 TRUE/YES(考虑到第一次将一次是在用户锁定屏幕时,第二次是在用户解锁屏幕时)。当此变量为 TRUE/YES 时,将调用警报。
我该怎么做?
我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
hasBlankedScreen,
CFSTR("com.apple.springboard.hasBlankedScreen"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
}
static void hasBlankedScreen(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
/*
if(isUnlocked){
[self myAlert];
} else{
isUnlocked = true;
}
*/
}
- (void) myAlert{
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"HEY"
message:@"Screen is unlocked"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[self pop];
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}
最佳答案
这很简单:
1) 将 (const void*)self
作为观察者传递给 CFNotificationCenterAddObserver
而不是 NULL
;
2) 在 hasBlankedScreen
中使用 (__bridge ViewController*)observer
而不是 self
。
完整代码:
- (void)viewDidLoad {
[super viewDidLoad];
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
(const void*)self,
hasBlankedScreen,
CFSTR("com.apple.springboard.hasBlankedScreen"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
}
static void hasBlankedScreen(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
if (self.locked) {
[(__bridge ViewController*)observer myAlert];
self.locked = NO;
} else {
self.locked = YES;
}
}
关于ios - 在 Darwin 通知中心回调上调用 UIAlert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37282038/
突然出现这个奇怪的错误。不确定 Xcode 是否已损坏。任何人都知道如何在 Xcode 中修复此错误。 代码是干净的,确保它在其他机器上工作正常,Xcode 设置或某些配置存在一些问题。 'time.
自从在 Xcode 9(以前的 8.2)中打开我的项目以来,几个静态库和框架目标无法编译并出现大量错误。这个循环依赖错误总是在顶部。 一个例子是 libzip 的静态库目标。问题源于系统 zlib 库
问题概述 我正在尝试学习如何构建交叉编译器,特别是在面向 i386-apple- 的 64 位 Intel OS X 主机上构建 GNU gcc 4.7.2 版本darwin(32 位英特尔)。但是,
我刚刚将我的 OS X 从 10.10.5 升级到了 OS X El Capitan 10.11。 我试图将我的 mac 端口更新到版本 2.3.3 ... Mac 端口收到此错误: $ sudo p
这段代码在快速访问 C 中的时间和日期函数时有什么问题?即使 difftime 函数在时差上是正确的,它给我的日期也有 3 天的偏差。 import Darwin var time1 = t
FOREWORD: This question is in regards to essential manpages that have seemingly disappeared from the
我正在尝试了解如何在 Mac 上重新映射内存映射文件(当我想扩展可用空间时)。 我看到我们在 Linux 世界的 friend 有 mremap 但我在我的 Mac 上的标题中找不到这样的功能。 /D
我是 nix 世界的新手,我使用 Mac OS X。我刚刚在我的 MacBook 上安装了 nix,并想使用 nix 来管理一些软件包,例如 Emacs 而不是 Homebrew。 我找到了这个仓库:
我需要测量 darwin 上各个线程的 cpu 使用率。在 linux 上我使用 getrusage(RUSAGE_THREAD, ...) 但它在 darwin 上不可用。 最佳答案 getrusa
我有一个用 C++ 编写的服务器,它在 osx 上运行时会泄漏 Mach 端口。具体来说,运行时 top我注意到它有大约 50000(在 #PORTS 下)。奇怪的是,我让它运行了一夜,第二天机器基本
当我尝试 swift package generate-xcodeproj 我得到 - :0: error: cannot load underlying module for 'Darwin' Ca
应用程序配置为在后台接收位置更新,以保持应用程序处于事件状态,并且当应用程序在后台时成功接收更新。 Darwin 通知也已配置,仅当该应用程序是前台的当前应用程序时才会收到通知。一旦应用程序进入后台,
在 Linux 上,sched.h 包含的定义 int sched_rr_get_interval(pid_t pid, struct timespec * tp); 获取进程的时间片。然而,OS X
我最近向应用商店提交了一个新的二进制文件并将其送去审核,但立即被拒绝并显示以下消息。 “不支持的操作 - 不允许应用程序收听设备锁定通知。”。经过一番深入研究后,我发现我们无法使用“com.apple
我对 Linux 还是个新手。 我在 Linux 环境中构建了一个应用程序,它使用基于 cgo ( https://github.com/mattn/go-gtk/) 的 gtk 库。该应用程序在其
我有一个 C 应用程序,我正在尝试为 Mac OS X 10.6.4 编译: $ uname -v Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53
我正在制作一个流媒体服务器,以在我的移动设备上查看我的网络摄像头的实时视频源。 我考虑使用 ffmpeg 、 VLC 和 DSS 并进行了以下设置,尽管跳过了帧:- video4linux2 > ff
我正在寻找移动视频流服务器,并找到 dss 和 mfpeg 服务器。 有人知道 dss 和 ffmpeg 服务器之间的区别吗?推荐哪一个? 谢谢你 最佳答案 如果您需要具有大量社区覆盖的服务器,请使用
不久前,我记得读过一篇杂志文章(我相信是《连线》),内容是将达尔文进化论应用于程序以创建更好的程序。基本上会产生一个程序的多个突变,并且将选择表现最好的一个进行下一轮突变。 不幸的是,我无法让这个主题
我有 vmware 工作站 14 pro 和 macOS Unlocker 3, 当我运行解锁器时,出现此错误: main() File "gettools.py", line 91, i
我是一名优秀的程序员,十分优秀!