Xcode project works in Simulator, not on device - objective-c

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. (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. And there were 3 such duplicate symbols.
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.
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. 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."
I want to show off to my friend, so I attach my iPhone 6, compile it, run it and when I select "Play" - crash!
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.
In the simulator, answers also has 3 items. On my iPhone, answers is nil.
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? Otherwise, I'm stumped.
Edit
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).
That solved it for me.
Works on both simulator and device now.

Related

AVFoundation Speech Synthesis on iOS 8 and XCode 6

I am having problems using AVSpeechSynthesis on iOS 8.0.2 and XCode 5. I tried it on the simulator and got a "Speech initialization error: 2147483665". I then tried it on my iPhone 5 and got no error but no speech.
In my .h file I import
import
and have #property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
In my .m file I synthesis the synthesizer
I have AVFoundation referenced in my frameworks
On my viewDidLoad I do the following
self.synthesizer = [[AVSpeechSynthesizer alloc] init];
self.synthesizer.delegate = self;
Later on in my code to control what is said I do the following
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:dialog];
utterance.rate = AVSpeechUtteranceDefaultSpeechRate;
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:#"en-au"];
[self.synthesizer speakUtterance:utterance];
I have CCViewController : UIViewController in my view controller.
Does anyone know what is wrong? Does AVFoundation work in iOS 8?
I saw a similar post on stack overflow which said to initialize my speaking #" " but that did not work.
Any help would be appreciated.
Thanks,
Greg
What you have should work with a small tweak, I think (see below), but only on a device and not the simulator. I replicated the same error message when I try to run your code or code I have that uses AVSpeachUtterance in the simulator. Not sure if this is a bug or just a limitation of the simulator. To get things working, try commenting out the line:
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:#"en-au"];
Does it work then? Without this line of code things working as they should for me on an iPhone 5 (8.0.2), however if I use any of the codes language codes shown here (What are the BCP-47 voice codes available for iOS 7 AVSpeechSynthesisVoice?), no text is spoken. The only way I can get things to work when I explicitly set the language is if I use #"en-GB", which is also the language the phone is configured for in settings. I can use another language code if I change the language of my phone in settings, say to US english and #"en-US".
As an FYI, the bug that required an initial bit of dummy text, i.e. #" " to get things working seems to be fixed in 8.0.2

UIScrollView does not scroll when an object is inside

I made a UIScrollView inside a UIViewController I have like 5 ViewControllers my problem is in the 4th one.
The UIScrollView I made does scroll when I put notting it it (so no label no button, no objects at all) but when I put even a label (or anything) in the UIScrollView it stops working.
Edit:
I have try'd making the same thing in a new project, for some reason it does work I think it has something to do with the fact that it is in the 4th ViewController and the new one I made, was made, in the First automatically made viewcontroller.
I do not yet have a answer please help.
My code:
viewcontroller.h
#import <UIKit/UIKit.h>
#interface viewcontroller : UIViewController
#property (weak, nonatomic) IBOutlet UIScrollView *ScrollerMdon;
#end
viewcontroller.m
#synthesize ScrollerMdon;
- (id)initWithNibName:(NSString *) nibNameOrNil bundle:(NSBundle *) nibBundleOrNil
{
self = [super initWithNibName: nibNameOrNil bundle:nibBundleOrNil];
if(self)
{
}
return self;
}
-(void)viewDidLoad
{
[ScrollerMdon setScrollEnabled:YES];
[ScrollerMdon setContentSize:CGSizeMake(320,1000)];
[super viewDidLoad];
}
#end
In xcode viewcontroller connection inspector my outlet ScrollerMdon is connected with *Scroll View(*which I inserted in my viewcontroller)
In xcode UIScrollView connection inspector my Referencing outlet ScrollerMdon is connected with viewcontroller.
Please help me I have been trying to solve this for 5 hours.. I can't stand it anymore.
Edit:
I try to make it possible for a single viewcontroller to hold like 17 textboxes I see no other way than doing it with a UIScrollView if there are any suggestions I would be really happy.
Edit2:
I have try'd to make it all aggain putting the same class on a different view controller and the other way around, I kinda rewrote the code and everything it's exactly the same as what I made in the other project but it does not work.(when an object is inside..)
2 foto's of my program.
Srry for the small and bad images, for some reason they moved without my permision but it is enough information I guess.(I use VMWare 8 with os x leopard on it)
foto 1
foto 2
Me Scrolling without items:
imgur.com/cd16I
Me desperately Scrolling with items:
imgur.com/hNUl1
Since I can only post 2 hyperlinks you have to open these yourself.
PS. please upvote this if you do not know the answer for I need a answer and there will probably be more viewers if it gets upvoted, ty.
Edit3:
I am now copying my entire code and build of the app in a different project hope this wil work :S.
I had the SAME exact problem that I ran into yesterday. Drove me nuts for hours... This was a brand new project that I just started like a week or so ago.
The thing is, I had another project that had the exact same setup essentially that I had started last summer that has no problems. Tabbed application, VC that has a UIScrollView with many uiviews, labels, images etc... works great.
So what changed from that project to this project? The version of Xcode that I started the project out in. The project from last summer did NOT have the AutoLayout enabled as an option. This new one did ( Xcode 4.6 ).
If I turn off "Use AutoLayout" for the entire project it works fantastic.
In the Utilities panel, click on the File Inspector tab. In the section for "Interface Builder Document" you'll see a checkbox for "Use AutoLayout". De-select that and re-build your app. Just found this trick not more than 10 minutes ago for my own project -- works great.
Hope this works for your project... good luck!
I found the solution it might not be the perfect solution but it works.
The problem seemed to be somewhere in my first project since I could make it work in other projects,
so I copy'd my entire project to a different project and this way it worked.
This solution won't explain what is wrong but I think it will solve your problem.
Copy the elements from the new project you created to the old one and replace the affected view controller. Copy also the class.
There must be something wrong with your connections but with the info you provided is impossible to check.
If that doesn't work then it must be something in the navigation (doubt it) or in some custom code you have on the class (very difficult if all the code you have is in the viewDidLoad as you've shown).

deploy to device results in frankenstein binary

I'm unsure if this is relevant to my question, but I'll start at the beginning: In my project I have a view controller which is instantiated dynamically by class name, like this:
NSString* className;
...className is set to a valid class name, e.g. "someViewController"
Class c = NSClassFromString( className );
UIViewController* vc = [[c alloc] init];
In the current build of the project, someViewController is simply a specialized UIViewController. However, in an old build of the project (which was previously deployed to my device), the view controller of type someViewController was a specialized UITableViewController.
I spent a bunch of time this morning trying to understand why when I ran the build on the device (deploy from XCode), it would crash with an odd call stack and a console message:
[someViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xeb62a0
With much experimentation I found that if I swapped out the someViewController with any other view controller I couldn't repro the problem. And if I renamed someViewController to someViewController2 I couldn't repro the problem. The problem was with the symbol name someViewController. Then it dawned on me that someViewController USED to be a UITableViewController and would have had the tableView:numberOfRowsInSection: implemented.
In any event; deleting the app off of the device and having XCode deploy a clean copy fixed the issue.
What I want to know is, why? How? I guess I've known in the back of my mind for a while that XCode does funky stuff when deploying - I've had issues before where old resources stick around in the deployed bundle after they've been removed from the project. But I wouldn't have expected there to be issues with Objective-C types.
Simply renaming a .h and .m file and then introducing a new .h and .m with the same name will cause problems. Not to xcode, but to you. Best is to copy files to a directory like /tmp, delete them from the project, later add them to the project as new with a different name.

Preprocessor Directive in xib?

Despite searching all over the place, I can't find the answer to my question. So let's see how good y'all are. :)
I'm working on an app that uses an NSPopover which is only available in 10.7 Lion but I want the app to compile for 10.5 and higher. I'm using a preprocessor directive to wrap the related popover code which seems to do the trick... However, the last piece I'm still getting errors on is the .zib in Interface Builder. How do I go about cleaning up the errors shown in the Issues Navigator stating "Class Unavailable: NSPopover on Mac OS X versions prior to 10.7"?
#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
#property (assign) IBOutlet NSPopover *popover;
}
#endif
#endif
The above works in xxx.h and xxx.m's, but how do I get around the .xib errors?
Despite the error (Red), it builds successfully. However am I wrong to expect the 10.7 features (popover) to work in 10.7 because they don't... What am I missing here?
You shouldn't use preprocessors for this but check for availability at runtime using NSClassFromString(). The preprocessor runs at compile time, thus it won't detect what system the app is being run on.
Create three nibs, one for each of 10.5, 10.6 and 10.7 and load the one you need (or do it in code), but pick which one at run time, not compile time, e.g.
MyVC *vc = nil;
if (NSClassFromString(#"NSPopover"))
{
vc = [NSViewController initWithNibName:#"MyVC-Lion" bundle:nil];
}
else if (/* check for 10.6+ only features */)
{
vc = [NSViewController initWithNibName:#"MyVC-SL" bundle:nil];
}
else
{
vc = [NSViewController initWithNibName:#"MyVC" bundle:nil];
}
// ...
Not a real answer to your question, apologies, but 2 possible workarounds: isn't it possible to create 2 versions of your xib, and depending on the target, compile on or the other? This would be a bit more work to maintain, but if your UI is pretty stable, this should be the easiest way.
Or you could add your "10.7 specific" UI component(s) programmatically instead of using the IB. If you just have one or a few popovers, it shouldn't be to difficult to do, and the proprocessor guards would work fine.

Objective C, Core Data issue

I'm following a tutorial in "More iPhone 3 Development. In the code, they have a line:
NSManagedObjectContext *managedObjectContext = appDelegate.managedObjectContext;
I get an error: "accessing unknown 'managedObjectContext' getter method" on that line.
I've downloaded his sample code and his program runs fine with that line of code. I've tried rewriting the code and I've even copied and pasted his code into my program, but I still get the error.
I am using the newest SDK, and I'm wondering if something might have changed so this getter method doesn't work anymore, but I do not get any warning about deprecation.
Does anyone know what is going on, or better yet, a better way to write this line and not get the error.
Thanks
LadyDev
When you create a core data project there's a method that is automatically created for you...
- (NSManagedObjectContext *) managedObjectContext
That's your AppDelegate's getter method for the managed object context. Also in the header file you will see that getter method defined:
#property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
So make sure you AppDelegate has these then you should not have that problem.
I had the same problem, i found that when I created the project it put 3 #property declarations in the SuperDBAppDelegate.m file which may be a new way of doing it i'm not quite sure. Anyway I took it from there and put it in the .h file and that fixed the error, however now I have other issues which I am still debugging but hopefully that works for you.