WatchKit crash due to accepted event even if not everything is loaded - crash

I have made an extension with a storyboard and some table view. In the simulator all is running ok, but when I try the app on Apple Watch I have some troubles. Since the Apple Watch is slower than the simulator it takes about one second to display the table views. During this time in the place of the table view is displayed nothing. If the user press the empty area that will be filled by the table view, as soon as the table view become visible it will be processed the event associated to the table view. I do not know why but this causes the app crash!!! I think everything would be solved if I do like in the other applications on my Apple Watch that while loading the view shows the rotating circle and not the elements of the view that are already in the storyboard (like buttons and labels) added at compile time.
I have to say that maybe the crashed are due to an use of NSTimer that modify some variables modified by the app, maybe I should use a mutex. But I do not figure how in the Apple Watch the application crashes (or it appears the rotating circle and keep rotating) but in the simulator is ALL OK. What can I do? Do you need additional information? Thanks!

Related

cocos2d mac application how to add splash screen when launching (Default.png)

i am migrating my iOS app onto mac. the loading time is a bit long (around 5 seconds) thus i need a splash loading screen (Just like Default.png image for iOS) but the project made from cocos2d template just shows a white screen. not sure about other apps. so is there anyway to set it?
I know that the screen size is not fixed on a mac app. but i have set a default size. and use auto scale in case of full screen mode.
EDIT:
I have tried a light weight loading scene as well but failed since the MainScene itself is light weight as well. I think the major loading time is due to the cocos2d environment set up.
In OS X a window appears when the application launches, it's not designed to use splash screens.You might want to reconsider that choice.
But if the window is still to slow to load or to display its contents, you can still do that but manually, it isn't easy like in iOS.You need to display another view inside the window until it loads.
EDIT
A little more of context: for example you can set in your xib file an image view containing the image do display.
Then you make start another thread that loads all the content that you need.After this, run a selector on the main thread that updates the window.
Based on my tests in Cocos2d 1.0.1 & 2.0 the basic Cocos2d OS X app launches really quickly.
This makes it seem pretty likely that it's something about your first scene that is taking a long time to load, or something else. Instruments can help you gather information about what your app is doing.
I suggest you make an initial lightweight cocos2d scene that will load quickly at startup and then load your second scene and transition to it. Ideally the loading of the assets for your second scene would be asynchronous (at least the ones that are slow). There are numerous blog posts on how to do this. (search for "cocos2d asynchronous loading" and you'll find many, such as this one: How to preload your game assets in a loading scene, though something more recent might be preferable).

MFMailComposeViewController causes other controls to change position

I have three UIViewControllers being shown modally on top of each other. The third one opens a MFMailComposeViewController and send an email. However, after dismissing that view controller, various controls on other view controllers (not necessarily in the chain of view controllers) have moved in position.
For example, after dismissing the MFMailComposeViewController, one of the labels on the parent ViewController has moved down by about 20px. A scrollview on it's parent has also moved down the same amount. If I enter a separate view controller from here, an imageview is displaced. They always seem to be a control near the top of the screen, and only one per screen.
Has anyone seen this before? I've checked all the code and there nothing which could be causing it. I'm having to reset the frame on these controls every time the screen is shown to prevent them from appearing out of place. But it makes no sense to me.
Thanks.
Have you tried presenting it from the parent view controller?? I had a similar problem and it fixed the issue.
It sounds like layout randomly isn't happening, somehow. I can think of a few things to try:
Check that you're not expicitly calling -layoutIfNeeded, especially in places like -setFrame: or -sizeThatFits: — it can cause a layout of the entire view tree, which will tend to do the wrong thing if layout is already happenin (on iOS 5 it can cause inconsistent layout; on iOS 6 I've observed it getting stuck in a layout loop). You also need to be careful around some methods which perform a layout as a side-effect (UIButton.titleLabel comes to mind — the fix is to call it before adding the view to the hierarchy).
If you're using autoresizing then it should just work — except I've seen it not work if the view isn't attached to a window when its frame changes.
If you're doing layout in -layoutSubviews, override -setFrame: to call -setNeedsLayout. The usual symptom is that "switch tabs, rotate, switch back" results in an incorrect layout.

Updating UITextView inside UIScrollView while scrolling makes the scrollView stop scrolling

I have a scrollView that contains 12 UIViews set as tiles. Each tile contains a textView.
The scrollView has pagination enabled. So, you have 12 tiles per page and you scroll horizontally.
I am updating the textView whenever I receive information from an API call.
This is updating the textView correctly, but I have a huge problem. Whenever the update happens, the scrollView actually scrolls to the view that was just updated. So whenever I load a new column of tiles, the scrollview stops when it begins loading it, even if it has momentum!
Any idea what might be causing this?
If I lazy load the cells without any information in them everything works right, so I'm thinking it has to do with me updating the textView.
I have already tried:
Using an NSTimer (and setting its mode to NSRunLoopCommonModes).
Using an NSOperationQueue and calling the main thread whenever I need to update UI changes.
None of those worked.
i think the solution lies within your post:
"Using an NSOperationQueue and calling the main thread whenever I need to update UI changes."
Whenever scrollView calls for willScroll, stop the current Images being downloaded & when the scroll view stops scroll & its delegate method is called start the new queue to download images.
My suggestion will be debugging it using instrument. In instrument there is a trace template named "Time profiler", you can actually see how much time your application spends on each tasks.
But if you are updating the textViews, of course the main thread will be blocked, so the scroll view stop scrolling until all the textViews are updated. So my suggestion will be tweaking the performance.
Maybe you are loading too much things in each textView?

iOS: Restoring the previously visible view when the app returns to the foreground?

I'm developing an iPhone (iOS 5+) app using storyboards. The first screen of the app is a splash/login screen that checks for Facebook credentials and enables you to read and accept Terms And Conditions. In case there are valid stored credentials and the TOC has been previously accepted, this view automatically makes a modal segue (using a cross dissolve effect) to the first "real" application view, a tab bar controller with three tabs.
I'm currently implementing backgrounding and foregrounding logic. The problem is that when pressing the home button and then coming back, the login screen is briefly shown before the correct pre-backgrounding view is restored. (The Default.png of the app is of the login screen background, so it might be either that or a backgrounding-time screenshot of the actual login screen; I haven't tested replacing Default.png yet to tell the difference.)
Why is this? As far as I can tell, backgrounding the app should just take a screenshot of the view that is visible on the screen when, say, hitting the home button, and restore that prior to restoring the actual view functionality when coming back to the foreground. In this case that would be one of the tabs of the tab bar controller. Is the modal segue between the login screen and the tab bar controller the culprit here, or something else?
(I've always felt that the cross dissolve modal segue from the login screen to the first "useful" screen is a bit dirty, since IMHO a modal segue seems to imply that what your segueing to is something you'll later dismiss to get back to the "from" screen. What I'm doing now is just leaving the target of the modal segue visible indefinitely. If that is the problem here, I'd love it if someone would suggest a better method of displaying, transitioning away from and "jettisoning" the login screen.)
OK, turns out this was just a simulator/device discrepancy regarding Default.png. This comment on another question made me think to check. Time to file a bug report.
If I recall correctly, Apple has some old demo code which "remembers" which view a navigation controller was showing before it went into the background.
By way of disclaimer, I haven't worked with storyboards, so I don't know the specifics of doing what you're trying to do.
If it were me, I'd create the view controller or controllers at launch, and then only add the login screen if deemed necessary by the app delegate's logic. Only then, after setting up the view hierarchy, do I present everything.
This accomplishes two things. My login screen only exists and is visible if necessary. Additionally, the login screen won't flash unessecarily. Oh, and as a third benefit, you can present any view you like.
I'd suggest, assuming the aforementioned demo code doesn't work for you, that you'll want to save some sort of reference, tag, or ID of the currently visible view in NSUserDefaults and read that out when setting up your view hierarchy on launch.

Best way to create floating notification iOS

I've got a tabbed iPad application with just about each tab running a UIWebView. I'm getting all sorts of callbacks, like when a user tries to leave the corporate site (which only displays the company site to users). In this case, I pop up a "toast" style window that tells them to click a button to open the page in Safari. I also pop it up with a spinner and no text to indicate that a page is loading. The approximate look that I'm going for is used in lots of applications, but you can see it best when changing the volume on the iPhone or iPad. It's just a translucent rounded square that fades in and out.
Right now I've got it implemented on one of my tabs, and I did it by creating the objects (a spinner, a label, and a UIImage with the square) and then programmatically hiding and showing them using [UIView beginAnimations] and changing the label's text. It works perfectly but I've got these nagging things hovering over my interface in Xcode, and it takes a lot of setup to accomplish if I wanted it to be in another tab, which I do. I can't help but think that there's a better way to accomplish this. I thought about making and adding a subview, but that would leave a white background to the toast. What I'm thinking is creating some sort of object that I can allocate in a tab's view controller whenever it's needed.
What are your guys ideas, or have you done this in the past? I see it in a lot of prominent applications, like Reeder, so I'm sure it's been done more eloquently than I have done it.
Matt Gallagher has a great class called LoadingView here Showing message over iPhone Keyboard. I use it.
MBProgressHUD is a popular library for this, as well.