[英]Xcode project works in Simulator, not on device
Still working on my flash card-themed app.仍在开发我的闪存卡主题应用程序。 Completely baffled.
完全一头雾水。 Lots of possibly salient info.
很多可能的重要信息。
I have a version which works flawlessly, both in simulator and on multiple devices.我有一个在模拟器和多个设备上都可以完美运行的版本。 But, I made a mistake when submitting to the App Store (wrong Bundle ID and Name), so I created a new project and copied and pasted the code and storyboard.
但是,我在提交到 App Store 时犯了一个错误(错误的 Bundle ID 和名称),所以我创建了一个新项目并复制并粘贴了代码和故事板。 (I didn't just move the files; I recreated them and copied the code.)
(我不只是移动文件;我重新创建了它们并复制了代码。)
First problem was that it wouldn't build because "duplicate symbol _answers in" RootViewController.o and DescendantViewController.o.第一个问题是它不会构建,因为“RootViewController.o 和 DescendantViewController.o 中的“重复符号 _answers”。 And there were 3 such duplicate symbols.
并且有 3 个这样的重复符号。
Yes, I have declared NSMutableArray *answers
in the implementation of both my RootVC and DescedantVC, so I concede that's suspect, except.... it's the exact same code as in the version that works.是的,我已经在我的 RootVC 和 DescedantVC 的实现中声明了
NSMutableArray *answers
,所以我承认这是可疑的,除了......它与工作版本中的代码完全相同。
Nevertheless, I saw an opportunity to clean up my code, so I created a @property (weak, nonatomic) NSMutableArray *answers
in my RootVC and changed the code in the root and descendant View Controllers to reference self.answers
.尽管如此,我看到了清理代码的机会,所以我在我的 RootVC 中创建了一个
@property (weak, nonatomic) NSMutableArray *answers
并将根视图控制器和后代视图控制器中的代码更改为引用self.answers
。 It compiles without any problems.它编译没有任何问题。
It runs in the simulator perfectly.它在模拟器中完美运行。 As I've just copied the entire code base to a new project, I test everything - no problems.
因为我刚刚将整个代码库复制到一个新项目中,所以我测试了所有内容 - 没有问题。 I'm very excited, so I do all the steps to submit to the App Store, except the last one "Submit for Review."
我很兴奋,所以我做了所有步骤提交到App Store,除了最后一个“Submit for Review”。
I want to show off to my friend, so I attach my iPhone 6, compile it, run it and when I select "Play" - crash!我想向我的朋友炫耀,所以我附上了我的 iPhone 6,编译它,运行它,当我选择“播放”时 - 崩溃!
The following line is the culprit.以下行是罪魁祸首。
answers = [self pickWrongAnswersIgnoringCard:questionCard];
Both in the simulator and on the device, the last line of the this method is:无论是在模拟器还是在设备上,这个方法的最后一行都是:
return wrongAnswers;
In both cases, wrongAnswers
is an array with 3 items.在这两种情况下,
wrongAnswers
都是一个包含 3 个项目的数组。
In the simulator, answers
also has 3 items.在模拟器中,
answers
也有 3 项。 On my iPhone, answers
is nil.在我的 iPhone 上,
answers
为零。
Does anyone have any idea what this could be?有谁知道这可能是什么? The only thing I can think of is that I created the project that works over a year ago and the one that fails today, so maybe some of the Apple settings in the two projects are different?
我唯一能想到的是,我创建了一个多年前可以运行的项目,而今天却失败了,所以也许这两个项目中的某些Apple设置不同? Otherwise, I'm stumped.
否则,我很难过。
The function, as requested:该功能,根据要求:
-(NSMutableArray *)pickWrongAnswersIgnoringCard:(FlashCard *)questionCard {
NSMutableArray *wrongAnswers = [[NSMutableArray alloc] init];
FlashCard *randomCard;
for (int i=1; i<4; i++) {
do {
randomCard = [self pickARandomCardFromDeck:wrongAnswersSource];
} while ([randomCard.name isEqualToString:questionCard.name] || [wrongAnswers containsObject:randomCard]);
[wrongAnswers addObject:randomCard];
}
return wrongAnswers; // device or simulator, wrongAnswers.count = 3
}
I figured it out, even if I don't fully understand.我想通了,即使我不完全理解。
I changed from @property (weak, nonatomic)
to @property (strong, nonatomic)
.我从
@property (weak, nonatomic)
改为@property (strong, nonatomic)
。
That solved it for me.那为我解决了。
Works on both simulator and device now.现在适用于模拟器和设备。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.