本文介绍了在越狱设备上自行重启应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 每次用户访问主屏幕时,我的iOS应用都可以自动重启吗?这适用于越狱设备 - 该应用程序不适用于App商店。 一般情况下,如何根据应用程序外的特定用户操作重启应用程序?解决方案 加速度计 如果你想做的就是make当您遇到某些加速度计条件时,您的应用程序会运行,您可以使用 Activator 。 Activator是一个很棒的应用程序,由,除了你的主UI应用程序,并拥有启动守护进程监控加速度计。 当您检测到您感兴趣的特定类型的动作时,您可以使用 op启动您的UI应用程序en 命令。如果这只是供您自己使用,只需从Cydia下载 open 包。如果要发布给其他人,请确保您的应用依赖打开以确保它已安装。例如,如果打包在Debian .deb包中,DEBIAN / control文件可能包含: 取决于:打开 以确保安装您应用的用户也将自动获得打开,您的应用需要。 解锁 您的其他问题用户解锁手机时启动应用程序。再次,我会使用你的启动守护进程来听取这种情况。在iOS 5上,当我解锁手机时,我会看到此通知: 拦截通知:com.apple.springboard.lockstate (我通过命令行运行 notificationWatcher 实用程序检测到这一点,而SSH'd我也可以从Cydia获得NotificationWatcher,作为Erica Sadun的 Erica Utilities 包的一部分) 所以,我会有你的启动守护进程注册com.apple.springboard.lockstate的Darwin通知。这样的事情: CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),// center self, // observer:如果回调不需要self onLockStateChanged,//回调 CFSTR(com.apple.springboard.lockstate),// name NULL,/ / object CFNotificationSuspensionBehaviorDeliverImmediately); 回调函数在这里: static void onLockStateChanged(CFNotificationCenterRef center,void * observer,CFStringRef name,const void * object,CFDictionaryRef userInfo){ //如果您需要访问权限成员数据(ivars): MyLaunchDaemon * this =(MyLaunchDaemon *)observer; // if(userInfo!= nil){ // CFShow(userInfo); //} NSDictionary * info =(NSDictionary *)userInfo; //我不确定userInfo对象是否对锁定状态事件有任何有用的 //描述 if(/ * unlocked * /){ //强制app打开,或从后台系统恢复(/ usr / bin / open com.mycompany.MyAppName); } } 屏幕锁定后,我看到同样的通知,或解锁,因此您可能需要让启动守护程序跟踪锁定/解锁状态,或检查 userInfo 对象以查看是否告诉您这是否是锁定或解锁事件。我确定还有其他方法。 更新:如果您想要帮助整理屏幕被锁定时是否发生通知或解锁后,您可以看到我的更新2 在此其他SO答案。 notify_get_state()可用于确定事件是开启还是关闭。 Is it possible that my iOS app can auto-restart, each and every time the user accesses their home screen? This is for a jailbroken device -- the app is not destined for the App store.In general, how can I make my app restart given specific user actions outside the app? 解决方案 AccelerometerIf all you want to do is make your app run when you encounter certain accelerometer conditions, you can use Activator for that. Activator is a great app, by Ryan Petrich, available on Cydia for free. It lets you configure your device to run any app (or toggle) whenever a certain user action is taken. That could be a home button press, power/lock button press, or accelerometer shake.If a basic shake isn't what you want, or you are building an app to give to many users, and don't want them to have to setup Activator themselves, then you probably need to write some code yourself.For example, you could write a Launch Daemon, in addition to your main UI app, and have the launch daemon monitor the accelerometer.When you detect the specific kind of motion you're interested in, you can launch your UI app with the open command. If this is just for your own use, just download the open package from Cydia. If this is for release to others, make sure your app depends on open to ensure that it's installed. For example, if packaging in a Debian .deb package, the DEBIAN/control file might have this:Depends: opento make sure users installing your app will also automatically get open, which your app needs.UnlockYour other problem concerns launching the app when the user unlocks the phone. Again, I would use your Launch Daemon to listen for this condition. On iOS 5, I see this notification when I unlock the phone: Notification intercepted: com.apple.springboard.lockstate(I detected this by running the notificationWatcher utility from the command line, while SSH'd into my phone. NotificationWatcher is also available from Cydia, as part of Erica Sadun's Erica Utilities package)So, I would have your launch daemon register for Darwin notifications for "com.apple.springboard.lockstate". Something like this:CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center self, // observer: can be NULL if callback doesn't need self onLockStateChanged, // callback CFSTR("com.apple.springboard.lockstate"), // name NULL, // object CFNotificationSuspensionBehaviorDeliverImmediately);where the callback function is here:static void onLockStateChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { // if you need access to member data (ivars): MyLaunchDaemon* this = (MyLaunchDaemon*)observer; //if (userInfo != nil) { // CFShow(userInfo); //} NSDictionary* info = (NSDictionary*)userInfo; // I'm not sure if the userInfo object has any useful // description for the lock state event if (/* unlocked */) { // force app to open, or resume from the background system("/usr/bin/open com.mycompany.MyAppName"); }}I see this same notification when the screen is locked, or unlocked, so you may need to have the launch daemon keep track of the locked/unlocked state, or inspect the userInfo object to see if that tells you whether this is a lock or unlock event. I'm sure there's other ways, too.Update: if you want help sorting out whether the notification occurs when the screen is locked or unlocked, you can see my Update 2 in this other SO answer. notify_get_state() can be used to determine whether the event is an on, or off, event. 这篇关于在越狱设备上自行重启应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 11:41