由于iOS框架在发布之前不允许本地通知执行代码,因此我正在寻找一种在越狱设备上实现代码的方法.
更新
好吧,我已经成功创建了一个守护进程,它在启动时启动并保持运行.但是,发布通知需要该UIApplication对象.根据文档,这个单例是由UIApplicationMain()方法创建的,对于常规应用程序来说main().由于我希望通知由守护进程发布,因此单例是零.
我可以创建一个实例UIApplication吗?或者以其他方式发布通知?
我已经尝试调用UIApplicationMain()然后在应用程序委托中发布通知,以及杀死应用程序,但这显示了一个黑屏暂时; 我想它启动了应用程序.此外,当应用程序无法启动时(当手机尚未完全启动时),它会导致守护程序崩溃.
这是代码的草图
int main(){
if(launchedBySpringBoard || launchedBynotification)
UIApplicationMain(...);
else if(launchedByDaeamon)
StartRunLoop();
}
void triggerdByRunLoopEveryXhours(){
downloadData();
if(isNewData())
postNotification();
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个在后台作为服务运行的网络监视器应用程序.屏幕打开或关闭时是否可以收到通知/电话?
它通过使用以下代码存在于Android中:
private void registerScreenOnOffReceiver()
{
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(screenOnOffReceiver, filter);
}
Run Code Online (Sandbox Code Playgroud)
然后在打开/关闭屏幕时调用screenOnOffReceiver.iOS有类似的解决方案吗?
编辑: 到目前为止我发现的最好的是UIApplicationProtectedDataWillBecomeUnavailable(检测iPhone屏幕是否打开/关闭),但它要求用户在设备上启用数据保护(密码保护).
注意:编辑中的下方是简单的代码,可以在没有原始程序完全复杂的情况下生成问题.
我正在尝试为越狱的iOS编写一个闹钟应用程序.我将UI设置为用于安排警报的独立应用程序,然后将警报信息保存到磁盘.保存文件由始终运行的启动守护程序读取,该守护程序处理实际调度警报.
我正在安排警报(编辑:在守护进程中)(NSDate *fireDate之前计算):
NSTimer *singleTimer = [[NSTimer alloc] initWithFireDate:fireDate
interval:0
target:self
selector:@selector(soundAlarm:)
userInfo:alarm
repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:singleTimer
forMode:NSRunLoopCommonModes];
[self.timers addObject:singleTimer];
[singleTimer release];
Run Code Online (Sandbox Code Playgroud)
编辑:上面的代码在一个名为的方法中运行,该方法createTimers被调用reloadData.reloadData从共享保存文件中读取有关计时器的信息,并在AMMQRDaemonManager初始化函数中调用它,以及每当管理器收到notify_postUI应用程序更新了保存文件的通知时.
的soundAlarm:方法(编辑:也在守护进程)为:
- (void)soundAlarm:(NSTimer *)theTimer {
NSLog(@"qralarmdaemon: sounding alarm");
extern CFStringRef kCFUserNotificationAlertTopMostKey;
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(NULL, 3, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionaryAddValue(dict, kCFUserNotificationAlertTopMostKey, kCFBooleanTrue);
CFDictionaryAddValue(dict, kCFUserNotificationAlertHeaderKey, CFSTR("Title"));
CFDictionaryAddValue(dict,kCFUserNotificationDefaultButtonTitleKey, CFSTR("OK"));
SInt32 err = 0;
CFUserNotificationRef notif = CFUserNotificationCreate(NULL,
0, kCFUserNotificationPlainAlertLevel, &err, dict);
CFOptionFlags response;
if((err) || …Run Code Online (Sandbox Code Playgroud) 我正在编写一个钩子来记录系统中的所有达尔文通知。我挂钩到以下功能:
CFNotificationCenterPostNotification
CFNotificationCenterPostNotificationWithOptions
NSNotificationCenter::postNotification
NSNotificationCenter::postNotificationName
Run Code Online (Sandbox Code Playgroud)
我看到很多日志。例如,当我解锁屏幕时,它会显示 SBDeviceLockStateChangedNotification。
但我期待诸如“com.apple.springboard.lockcomplete”之类的事件或类似此处的其他事件
不知道为什么我无法捕获类似达尔文的通知。任何帮助表示赞赏。这是审查的代码
#include <notify.h>
#include <substrate.h>
#include <sqlite3.h>
#include <string.h>
#import <CoreFoundation/CFNotificationCenter.h>
//#include "CPDistributedMessagingCenter.h"
#import <CoreFoundation/CoreFoundation.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
//#import <SpringBoard/SpringBoard.h>
// init CFNotificationCenterPostNotification hook
void (*orig_CFNotificationCenterPostNotification) (
CFNotificationCenterRef center,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo,
Boolean deliverImmediately
);
void replaced_CFNotificationCenterPostNotification (
CFNotificationCenterRef center,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo,
Boolean deliverImmediately
){
NSLog(@"CFNotificationCenterPostNotification: %@", name );
orig_CFNotificationCenterPostNotification(center,name,object,userInfo,deliverImmediately);
}
void (*orig_CFNotificationCenterPostNotificationWithOptions) (
CFNotificationCenterRef center,
CFStringRef name,
const void …Run Code Online (Sandbox Code Playgroud)