How do I duplicate iPad display over TV out? - cocoa-touch

Is it possible to simply duplicate ipad display to TV out (assuming both have same resolution)?
Code like this doesnt seem to work (it is a pretty naive implementation)
int i=0;
for (UIScreen *screen in [UIScreen screens])
{
if(i>0)
{
UIWindow* extWindow = [[UIWindow alloc]init];
extWindow.screen =screen;
[extWindow addSubview:viewController.view];
[extWindow makeKeyAndVisible];
}
i++;
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];

Code like this doesnt seem to work (it
is a pretty naive implementation)
This code looks like a mishmash. I haven't used external screens before, but your inner if block is creating anonymous UIWindow objects, assigning a property, and then leaking them at the end of the block (no release) -- and that definitely won't do what you intend.
You should consult the iPad Programming Guide, specifically, Support for External Displays and Projectors, which summarizes how your code should be written.

If you need this for a demo presentation, then there are few apps that will duplicate the screen for you while running your app like TVOut, TVOut2, Screenspltr. However there is a catch, these apps are not approved by Apple therefore are not in the app store, in order to install them you'll need to jailbreak it and it comes with the involved risks. However for a quick dome it is probably the best solution.

Related

Parse Starter Project for iPad

I know it's very vague and is asking a lot but does anyone know how to convert the standard iOS starter project from iPhone to iPad (both is best)? Or does anyone know where I can download one. I am a new iOS developer and am trying to start learning with Parse.
I am referring to this project https://www.parse.com/downloads/ios/parse-starter-project/latest
P.S. Just because this question isn't perfect doesn't mean you have to go and down vote and flag it for removal I don't have a lot of points already no need to lose even more :)
Not being able to see this sample project, it's hard to say for certain what it will take.
At bare minimum go into your project summary, and select "Universal" for the device support.
Above and beyond that, it just depends on what the app is and how it's structured. For NIBs, you will want a NIB for iPhone and one for iPad. I find it easy to abstract this away so that I can simplify my view loading:
MyController *myController = [[MyController alloc] initWithView:#"MyControllerView" bundle:nil];
Then in a category, I'd define initWithView similar to:
#implementation UIViewController (Universal)
-(id) initWithView:(NSString *)view bundle:(NSBundle *)nibBundle{
bool isIpad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
NSString *nibName = [NSString stringWithFormat:#"%#_%#", view, (isIpad ? #"iPad" : #"iPhone")];
return [self initWithNibName:nibName bundle:nibBundle];
}
#end
But, that's just one aspect of supporting both devices. In reality the subject is rather specific to the app you're working on. Things like OS support (e.g., am I only targeting iOS 6 or higher) play a factor in things.
I have solved it now, if anyone needs the files email me turboecreations#iCloud.com I would upload them but I dont want my MediaFire and other accounts to be removed if I run into copyright issues.

Upgrading app from IOS4 to IOS5

I have an IOS5 app which uses following function
[self.presentingViewController dismissModalViewControllerAnimated:YES];
and who works perfectly on IOS4 but suddenly I discovered that this function doesn't exists on IOS5 so I had to use this other equivalent one
[self.parentViewController dismissModalViewControllerAnimated:YES]
Now I've got the following issue: IOS4 users are not able to install my app due to this non existing function in IOS4 and what is even worse, the app is available on Apple's App Store but is only functional of IOS5 users. Another related issue us that the app suddenly stopped working on iPads equipped with Wifi, those connected to 3G networks operate normal.
Is there anything I missed trying to compile this new app version?
Thanks in advance!
You can check for existence of the property like this:
if([self respondsToSelector:#selector(presentingViewController)])
[self.presentingViewController dismissModalViewControllerAnimated:YES];
else
[self.parentViewController dismissModalViewControllerAnimated:YES];
Code it this way:
if ([self respondsToSelector:#selector(parentViewController)])
[self.parentViewController ...];
else
[self.presentingViewController ...];
(This is uncompiled, untested, etc.)
The point is that you can (and should) test for capabilities, and then act accordingly. In this case, if the iOS5 method is available, use that one. If not, use the old one, which also means its a pre-iOS5 device.
The way to go is twofold:
compiling your app against the latest SDK version, but also set the deployment target to the oldest version that you want to support; this will ensure that the app is listed properly in the App Store;
checking before using any method/feature that is only available on a later version; this will ensure that you app will not crash and can be done by means of conditional compilation, e.g.:
k
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
if ([[UIApplication sharedApplication] respondsToSelector:#selector(beginBackgroundTaskWithExpirationHandler:)])
{
UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication] eginBackgroundTaskWithExpirationHandler:^{}];
// Perform work that should be allowed to continue in background
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}
#endif
this is quite convoluted if you have to do it in many places. You may have a look at this very good post to learn how to improve upon that example.
I have built a category that add presentingViewController on iOS 4.
(It disables itself on iOS 5.)
It works seamlessly; Just include 2 files.
Please see backward-modal.
I hope this benefits you as much as it does to me; It makes your code more clean!

Better way to detect if isIpad?

I have an universal app that changes the screen layout based on what device the user has.
It seems to work pretty good, but I've had one user call in (and send me screen shots) of his iPhone 4 showing him the iPad view instead of the iPhone view. I haven't been able to duplicate it on any of the phones we have around here, but I'm wondering if there there is a better way to do this since iOS 4.3 has come out.
+(BOOL)isIpad{
return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
}
Alternately, is there just a way to detect screen size? I mostly use this to determine how wide elements in a table should be, but if Apple comes out with iPad 3 with retina display, it would be nice to have the app just adjust everything accordingly.
Also useful if the app is in portrait or landscape. Make it so that it just anchors to the edges like elements in WPF.
When loading XIBs for a universal app this, or what you're already doing, seems to be the only way:
NSString *xibName = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)?#"SomeView~iPad":#"SomeView";
As for screen size this should work:
CGRect screenSize = [[UIScreen mainScreen] bounds];
This is like a bazillion years old, but came across it in google so I figured I'd post a poorly documented but very useful feature. If you add ~ipad to the end of the filename for your iPad specific nib it will automatically load that one instead. Same logic as #2x for loading images. So your iPhone nib would be named myview.xib and your ipad myview~ipad.xib and iOS will correctly load the ipad version wherever needed. Fancy!
UIUserInterfaceIdiomPad is now deprecated. The new way to do it would be using TraitCollections. It can only be called on Views.
-(BOOL) isiPad{
return self.view.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular && self.view.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassRegular;
}
Refer Apple Documentation here
Probably it has a previous version of the app and conflict with the new!
Try to remove old one and reinstall new! It works! I already encountered this issue.

iPhone SDK: How to account for UI layout differences, iPhone vs iPad?

If I have a universal app (runs on both iPhone & iPad), how do I account for UI layout differences in code if the UI differs between the devices?
If I am using a XIB, I can simply load a different XIB depending on the device and use the same code. Correct?
If I am creating my UI programmatically, though, how should this be handled? Is there a better way than if/elsing my way through the code and looking at the device type? I understand it's doable this way, it just doesn't seem very elegant.
if (isiPhone)
{
UIView *myCommonView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, 50.0)];
myCommonView.backgroundColor = [UIColor colorWithPatternImage:iPhoneSpecificImage];
// bunch of other conditional code
}
else
{
UIView *myCommonView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.0, 150.0)];
myCommonView.backgroundColor = [UIColor colorWithPatternImage:iPadSpecificImage];
// bunch of other conditional code
}
A much better alternative to using loads of if/else statements is to have multiple app delegates. An easy way to do this is to create an AppDelegate_iPhone & AppDelegate_iPad and respectively bind them (in IB) to the different XIBs that get loaded on launch. Now you have a way to programmatically add different items to each delegate.
This also can lead to an issue where you want to share UI elements between the delegates. In this case, you can create shared views that are used by both delegates (just import the view controller in both cases).
The code should structurally look something like this.
Unfortunately, programmaticaly if/elsing is the only way to do this. But when you think of it it's not that bad. Apple allows you to produce 2 different apps from the same code for 2 different devices.

Can I disable UIPickerView scroll sound?

I want to disable the annoying clicks that the UIPickerView generates upon scrolling up and down. Is there a way to do this? I want to play short sounds for each item that the picker view lands upon. It gets ruined by the built in sound.
I understand that the picker sounds can be turned off globally by switching off the keyboard sounds in iPhone/iPod settings. But is there a way to programatically do this?
Any help will be much appreciated!
Thanks
I've been struggling with a UIPickerView sound issue, and even though it's only partially relevant to the original question, I'm posting the problem/solution here because this topic keeps coming up in my search results so I think anyone else in the same boat may end up here too…
I needed to initialize a UIPickerView to restore the currently selected row from saved data. Simple, right? In viewDidLoad, just call the selectRow:inComponent:animated method of UIPickerView:
[myPicker selectRow:currentRowIndex inComponent:0 animated:NO];
This works as expected, but has a side effect that it generates a single "click" sound as if the user had scrolled the control. The click sound only occurs when running on a device (not the simulator), and only if the device has iOS 3.x installed (I tested with 3.1.3 and 3.2). This was apparently a bug in iOS that was fixed starting with iOS 4.0. But if you need to target Gen1 iPhone, you're stuck with iOS 3.1.3 where this problem is present.
I discussed the issue with Apple DTS, but they were unable to suggest any workaround other than upgrading to 4.0. I asked if they would make an exception and permit the use of the undocumented setSoundsEnabled mentioned above (which does actually solve the problem). The answer was, "There are no exceptions."
After some additional detective work, I discovered that you can prevent the sound from occurring by temporarily removing the UIPickerView from the superview, call selectRow, then re-add it to the superview. For example, in viewDidLoad:
UIView *superview = [myPicker superview];
[myPicker removeFromSuperview];
[myPicker reloadAllComponents];
[myPicker selectRow:currentRowIndex inComponent:0 animated:NO];
[superview addSubview:myPicker];
This gets rid of the extraneous click sound without using undocumented/private APIs so should pass Apple's approval process.
After using this specific undocumented api for over a year on the App Store Apple finally asked me to remove it from my App. It is very frustrating for audio apps to have that damn click sound. The best advice is to share with users that the picker sound can be disabled globally in the settings application under "Sounds" and setting "Keyboard Clicks" to "Off". I also strongly recommend visiting https://bugreport.apple.com/ and filing a bug for UIPickerView, as it can cause distortion in audio applications when the picker click is played.
they have just rejected an app of mine because the use of undocumented api's...thats one of them.
Someone I know says he got this past the App Store review just last week:
// Hide private API call from Apple static analyzer
SEL sse = NSSelectorFromString([NSString stringWithFormat:#"%#%#%#", #"set",#"Sounds",#"Enabled:"]);
if ([UIPickerView instancesRespondToSelector:sse]) {
IMP sseimp = [UIPickerView instanceMethodForSelector:sse];
sseimp(self.thePicker, sse, NO);
}
There is an undocumented way (I'm actually not sure if it is still available in iphone 3.0) but here it is any way
#import <UIKit/UIKit.h>
#interface SilintUIPickerView: UIPickerView
{ }
- (void) setSoundsEnabled: (BOOL) enabled;
#end
use this subclass instead and call [view setSoundsEnabled: NO]
I'm interested in knowing how it goes in the latest SDK, give it a shot and let us know.
Could this trick work? Someone was able to suppress the camera shutter sound effect by playing an inverted copy of the sound at the same moment: https://stackoverflow.com/a/23758876/214070
Maybe this not the answer for this particular question, but I had a similar problem - set minimumDate for datePicker, and I wanted set it without annoying "click" sound. After some time found very simple solution:
datePickerCustomTime.minimumDate = [[NSDate date] dateByAddingTimeInterval:300]// min time to set = now + 5 min
[datePickerCustomTime setDate:[[NSDate date] dateByAddingTimeInterval:300] animated:NO];
I found small quickie solution for this try below
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, yPickerView, VIEW_WIDTH, PICKERVIEW_HEIGHT)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
pickerView.alpha = 0.8f;
pickerView.tag = fieldTag;
[pickerView selectRow:pickerViewSelectedIndex inComponent:0 animated:NO];
set the animated:NO for selectRow: method