iOS ternary conditional operator implementation is picky only on device? - iphone

I'm using iOS SDK 4.2.
I think that the ternary conditional op is(?) implemented differently on the simulators (iPhone4.1, 4.2. iPad 3.2, 4.2) than on actual devices. Because:
iPad ? xibName = #"MyViewController-iPad" : #"MyViewController";
works perfect on those simulators but fails on my iPhone 4 (4.1)
while writing this way:
xibName = (iPad) ? #"MyViewController-iPad" : #"MyViewController";
allows it to work on both the simulators and device.
Anyone can tell why? Is it a bug? Is the "2nd version" better and i should always write that way?
it's strange how compiler accepts both and simulators work with both but the device only accepts one... maybe a bug for apple to check out?

These statements are not equivalent.
// iPad ? xibName = #"MyViewController-iPad" : #"MyViewController";
if ( iPad ) {
xibName = #"MyViewController-iPad";
} else {
#"MyViewController"; // Effectively a NOP
}
// xibName = (iPad) ? #"MyViewController-iPad" : #"MyViewController";
if ( iPad ) {
xibName = #"MyViewController-iPad";
} else {
xibName = #"MyViewController";
}
For !iPad ( like say, on an iPhone 4 ) with the first statement xibName would not get set at all, I am guessing you only ran an iPad simulator, not an iPhone.

Related

SCNCamera.exposureOffset not working in iOS13

SCNCamera.wantsHDR is true. Yet any changes to SCNCamera.exposureOffset are not visible on iOS13 devices. But it is working perfectly fine on iOS12.
if let camera = self.sceneView.pointOfView?.camera {
camera.exposureOffset = -5
}
You said absolutely right, if someone wanna use exposureOffset instance property in SceneKit, he/she needs to activate a wantsHDR property at first:
var wantsHDR: Bool { get set }
In real code it might look like this:
sceneView.pointOfView!.camera!.wantsHDR = true
sceneView.pointOfView!.camera!.exposureOffset = -5
But there's a bug in iOS 13 and iOS 13 Simulator. However, if you disable allowsCameraControl, exposureOffset works fine.
sceneView.allowsCameraControl = false
Here's how exposureOffset changes from -2 to 2:

SKAction scaleTo not working on iPhone 5S

I've found a strange behavior while using the iPhone 5S as development-target(Simulator and real device).
I'd like to scale a SKSpriteNode with an SKAction.scaleTo. This works fine on the iPhone 4S and the iPhone 5 simulator(Tested with iOS 7.0.3 and iOS 8).
But on the iPhone 5S simulator, the node doesn't scale. Also on my real iPhone 5S it doesn't scale.
Here is my code:
for tile in tileArray{
if(tile.color == searchColor){
var action = SKAction.scaleTo(0.5, duration: 0.5)
var action2 = SKAction.scaleTo(1, duration: 0.5)
tile.runAction(SKAction.repeatActionForever(SKAction.sequence([action, action2])))
}
}
EDIT:I've now found out, that the if-block doesn't get called on the iPhone 5S. I don't know why. For the other iPhones it works.
But as you see, the two colors are the same:
UIDeviceRGBColorSpace 0.203922 0.286275 0.368627 1
UIDeviceRGBColorSpace 0.203922 0.286275 0.368627 1
How is that possible?
Important: Other SKaction.scaleTo actions are working without any problems.
You are not comparing colors, you are comparing pointer values:
if(tile.color == searchColor)
This tests whether tile.color and searchColor both point to the same memory address. Depending on how the color is created, these addresses may be different. Try testing the individual color components as in:
if (tile.color.r == seachColor.r && tile.color.g == searchColor.b && etc ..)
Note that equality for floating point values is "relative".
The cause is the UIDeviceRGBColorSpace, which is different on the iPhone 5S. So I had to create an object-class which has also a name in it. Now I have to add the colornames to the class too, but I can compare the colors that way:
var color1 = ColorClass("myRed", color:theColor)
var color2 = ColorClass("myRed", color:theColor2)
if(color1.name == color2.name){
}
Of course this fix is really case-dependant. So for many others, this solution won't be good enough for their purposes.

corona sdk iphone 4s 5.1.1 no sound

I don't have sound in apps on iphone 4s 5.1.1
tested my app + 2 (unmodified)examples from sample code
even when i send notifications - i get vibration (if with sound) - without sound i don't get vibration but in both cases sound does not play. not it notification not in app
Help!
I tried using ggmusic and ggsound libs by Glitched Games. Both of witch implement the new audio api.
here is some code so i meet the QUALITY STANDARTS
local supportedAudio = {
["Simulator"] = { extensions = { ".aac", ".aif", ".caf", ".wav", ".mp3", ".ogg" } },
["IOS"] = { extensions = { ".aac", ".aif", ".caf", ".wav", ".mp3" } },
["Android"] = { extensions = { ".wav", ".mp3", ".ogg" } },
}
Ok guyz, the thing is - you should check that switch on the right side that turns off sounds. Your media playback will play via loudspeker, but sounds dont. Turn sounds on and it fixes it.
Lame apple user I am.
Cheers!

Code doesn't work on iPhone but works on simulator

I have this code in my live chat.
if (TRUE && (balloonsOn != NO || !htmlStart)) {
balloonsOn = TRUE;
htmlStart = [self createChatLines: balloonsOn ? #"htmlformat-balloons" : #"htmlformat"];
if (chatLines > 0){
chatLines = 0;
[self updateView];
}
}
On the simulator it works fine but on the phone it doesn't work. It has worked before many times but now it stopped working on the phone. Why is this happening?
As far as I can see, there should be nothing that wouldn't work on the iPhone.. The only thing I can suppose, is you are using that strings without caring of the case-sensitiveness of iOs. The simulator is case insensitive but iOs is.. Let me know :)
What is the variable 'TRUE' ? I think having that as a variable name is probably the issue, rename it something else and see if it works.

Detect Headphones Unplugged - Monotouch

Is there a way to detect if headphones are unplugged in Monotouch? I am trying to look for the AudioSessionAddPropertyListener method but don't see it. What this method ported over?
Here is Apple's docs: http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/doc/constant_group/Audio_Session_Interruption_States
If anyone wants to see the code for how to do this, you can do the following:
AudioSession.PropertyListener p = delegate(AudioSessionProperty prop, int size, IntPtr data) {
NSDictionary propertyDictionary = new NSDictionary(data);
if (propertyDictionary.ContainsKey(NSObject.FromObject("OutputDeviceDidChange_OldRoute")))
{
string oldRoute = propertyDictionary.ValueForKey(new NSString("OutputDeviceDidChange_OldRoute")).ToString();
if (oldRoute == "Headphone")
{
if (audioPlayer != null)
{
audioPlayer.Pause();
}
}
}
};
AudioSession.AddListener(AudioSessionProperty.AudioRouteChange, p);
Is there a way to detect if headphones are unplugged in Monotouch?
I'm not sure but...
I am trying to look for the AudioSessionAddPropertyListener method but don't see it. What this method ported over?
The native call to AudioSessionAddPropertyListener maps to MonoTouch's AudioSession.AddListener static method.