【问题标题】:Simple UIAlertView app fail on ios 5.0.1ios 5.0.1 上的简单 UIAlertView 应用程序失败
【发布时间】:2012-03-25 11:17:38
【问题描述】:

我目前正在使用 Cycript 弹出一个跳板警报窗口,例如:

#!/usr/bin/cycript -p SpringBoard
var message = [[UIAlertView alloc] init];
message.title = "Title";
message.message = "Message";
[message addButtonWithTitle:@"Dismiss"];

[message show];

但我想摆脱这种方法,因为 Cycript 不适合生产。

使用theos,我做了一个工具项目,我的main.mm是:

int main(int argc, char **argv, char **envp) {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSLog(@"Start");

        UIAlertView *alert = [[UIAlertView alloc] init];
        NSLog(@"1");
        [alert setTitle:@"Title"];
        NSLog(@"2");
        [alert setMessage:@"Message"];
        [alert addButtonWithTitle:@"Dismiss"];
        [alert show];
        [pool release];
        return 0;
}

Makefile 是:

include theos/makefiles/common.mk

TOOL_NAME = cmdWindow
cmdWindow_FILES = main.mm
cmdWindow_FRAMEWORKS = UIKit Foundation

include $(THEOS_MAKE_PATH)/tool.mk

它编译得很好,但是当我在我的 iphone 上运行它时,我看到了:

iPhone:/tmp root# ./cmdWindow 
2012-03-25 06:33:18.801 cmdWindow[2845:707] Start
2012-03-25 06:33:18.851 cmdWindow[2845:707] 1
Trace/BPT trap: 5

任何想法为什么这会崩溃?是不是因为没有将命令行工具挂接到跳板的逻辑(比如 cycript 的 -p 开关)?

我已经在 /opt/theos/include 中尝试了 rpetrich 和我自己的自定义 5.0.1 标头 - 相同的行为。

【问题讨论】:

    标签: objective-c ios5


    【解决方案1】:

    在运行循环启动并 UIApplication 引导之前,您无法显示警报或任何 UI。从 SpringBoard 正确注册和启动的应用程序执行这两项操作,您的警报将显示。

    或者,让 SpringBoard 使用 CFUserNotification 系列 API 代表您显示警报。

    【讨论】:

      猜你喜欢
      • 2012-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多