在 xcode iPhone SDK 中添加 UIWindow
我正在创建一个项目,其中我必须更改 main.m 文件,以便 UIApplication 不会立即出现,因此我从 main.m 中删除了以下行
int retVal = UIApplicationMain(argc, argv, nil, nil);
,并从 AppDelegate 中删除了这些行
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}
并且我添加了我的一些行。现在 UIWindow 默认情况下不会出现,这是正确的。但现在执行我的代码后,我想创建一个窗口并显示一些消息。
main.m中没有UIApplication时如何创建UIWindow?
I am creating a project in which i have to change the main.m file, so that UIApplication doesnt appear straight away, so i deleted the following line from main.m
int retVal = UIApplicationMain(argc, argv, nil, nil);
and deleted these lines from AppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}
And i have added some lines of mine. Now UIWindow doesnt appear by default, and rightly so. But now after my code is executed, i want to create a Window and display some message.
How to create a UIWindow when there is no UIApplication in main.m?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想从守护进程启动应用,请使用
SBSLaunchApplicationWithIdentifier
。如果要启动 URL,请使用
-[UIApplication openURL:]
或较低级别的GSEventSendApplicationOpenURL
。如果您只想显示警报,请使用
CFUserNotification
。 (是的,它适用于 iPhoneOS。)http: //developer.apple.com/mac/library/documentation/CoreFoundation/Reference/CFUserNotificationRef/Reference/reference.html
If you want to launch an app from a daemon, use
SBSLaunchApplicationWithIdentifier
.If you want to launch a URL, use
-[UIApplication openURL:]
or the lower-levelGSEventSendApplicationOpenURL
.If you simply want to display an alert, use
CFUserNotification
. (Yes it works on iPhoneOS.)http://developer.apple.com/mac/library/documentation/CoreFoundation/Reference/CFUserNotificationRef/Reference/reference.html
最有可能的是,不启动 UIKit 并不是您正在寻找的解决方案。尝试不显示任何 UI(不要从
applicationDidFinishLaunching:
返回)并在其中(或从中调用的内容中)执行您需要执行的操作。或者,您可以使用UIActivityIndicatorView
显示一个漂亮的加载屏幕。另请注意,如果您的应用程序在启动后 20 秒内未完全启动(显示某种 UI 并响应事件),SpringBoard 或操作系统将自动退出您的应用程序。此外,用户不喜欢等待:)。
编辑:由于您不是在制作 UIKit 应用程序,所以不要梦想能够在中间启动 UIKit:您不能。这需要一个单独的组件挂钩 SpringBoard 来完成。
Most likely, not starting UIKit is not the solution you are looking for. Try just not showing any UI (don't return from
applicationDidFinishLaunching:
) and do what you need to do in there (or in something called from that). Or, you could just show a nice loading screen with aUIActivityIndicatorView
.Also, note that if your application has not fully launched within 20 seconds of startup (showing some sort of UI and responding to events), SpringBoard or the OS will automatically quit your application. In addition, users don't like to wait :).
Edit: Since you are not making a UIKit app, stop dreaming of being able to start UIKit in the middle: you can't. This requires a separate component hooking SpringBoard to accomplish.
为什么你试图从守护进程打开一个窗口?这似乎是一个非常糟糕的主意,而且正如你所注意到的,实际上很难做到。
相反,创建一个应用程序来执行您想做的事情,并在您想要显示窗口时从守护进程启动它 - 通过 URL 处理或其他方式。但基本上,该应用程序和您的守护程序在启动并运行后就可以进行通信,并且它可以在远离守护程序域的地方执行所有 UI 操作。
WHy are you trying to open a window from a daemon? It seems like a super-bad idea, and as you note hard to actually do.
Instead, create an app to do what you want to do and launch it from the daemon when you want to show a window - either via URL handling or some other means. But basically that app and your daemon can communicate once it's up and running, and it can do all the UI stuff away from the domain of the daemon.
感谢 KennyTM 的出色建议,我实现了我想要做的事情。
这就是我所做的
1)我创建了我的应用程序,在其中我为我的应用程序做了所有的事情,然后将所有这些设置写入一个文本文件,并使我的应用程序创建该txt文件并将其放置到/ private / var / mobile / SomeFile .txt(作为移动用户,您的应用程序可以在不干扰权限的情况下进行写入)
2)然后我在 xcode 中创建了另一个应用程序(基于窗口),删除了委托(h/m)文件并编写了我自己的 main函数,其中我从我的其他应用程序在第一步中创建和写入的文件中读取(/private/var/mobile/SomeFile.txt)。
3)我创建了一个plist(您可以在此处找到有关创建LaunchDaemon的帮助http://www.tuaw.com/2008/02/21/tuaw-responds-iphone-lojack/)
4) 我制作了该 plist,以便在步骤 2 中每 60 秒读取我的应用程序 (1分钟),如果条件为真,第二步中的应用程序将使用 CFUserNotificationDisplayAlert 显示警报(感谢 KennyTM 的指导)。
我目前遇到的唯一问题是我必须手动将 launchDaemon 放置在 /Library/LaunchDaemons 目录中,但使用 root 进行 SSH,因为我无法/我的应用程序无法写入该目录。
i achieved what i was trying to do, thanks to KennyTM for his great advices.
This is what i did
1) i created my app in which i did all the stuff for my app and then wrote all those settings to a text file and made my app create and place that txt file to /private/var/mobile/SomeFile.txt (This is the place where as a mobile user, your app can write without messing with permissions)
2) Then i created another app in xcode, (Window Based), deleted delegate (h/m) files and wrote my own main function, in which i read from the file my other app create and wrote at in the 1st step (/private/var/mobile/SomeFile.txt).
3) I created a plist (You can find help on creating a LaunchDaemon here http://www.tuaw.com/2008/02/21/tuaw-responds-iphone-lojack/)
4) I made that plist to read my app in step 2 every 60 sec(1 min) and if condition is true, the app in the 2nd step will display an Alert using CFUserNotificationDisplayAlert (thanks to KennyTM for his guidance).
The only problem i am currently having is that i have to place that launchDaemon in /Library/LaunchDaemons directory manually but SSH using root, because i cant / my app cant write to that directory.