infinitered / rmq

RMQ - RubyMotionQuery
MIT License
307 stars 52 forks source link

device.simulator? is broken in iOS9 SDK #293

Closed HealsCodes closed 9 years ago

HealsCodes commented 9 years ago

The iOS9 simulator runtime now identifies itself as iPhone, iPad etc. and no longer includes the 'Simulator' suffix.

@_simulator = !(UIDevice.currentDevice.model =~ /simulator/i).nil? if @_simulator.nil?

Won't work in that case.

GantMan commented 9 years ago

any stack overflows on how people are detecting simulators now? I'm coming up blank.

HealsCodes commented 9 years ago

Since it's still beta / technically NDA Stack Overflow is rather quiet about iOS9. For C/Objective-C there is UIDeviceHardware available from this gist which should still work. But I'm not sure that it's portable to RubyMotion.

squidpunch commented 9 years ago

do you guys have anything in your apps that specifically check if its the simulator? I wonder how used this is - I don't have anything in my apps that I can recall that check simulator versus hardware. Just curious!

Either way I see the options are:

twerth commented 9 years ago

David, I thought we had this in rmq already. I'll poke around, we've done this for sure.

HealsCodes commented 9 years ago

@squidpunch - for my part I'm actually using this. I have an extension on motion_print to log to the REPL on simulator and to a special logger view on device (and also log critical errors using NSLog on device only). There's also a bunch of other features that I can't easily factor out that simply get disabled on the simulator.

squidpunch commented 9 years ago

@Shirk ok cool, was just curious of the use case simply because I dont do it - those sound like great ideas though!

@twerth yeah its there - the problem is iOS9 changes it from what @Shirk posted

HealsCodes commented 9 years ago

I completely agree with both of you @squidpunch and @twerth but I think it's unlikely that this was changed by accident. The iOS9 Simulator runtime made some huge steps in closer mimicking the real thing (for one: the simulator now actually boots and has the same boot animation than real hardware).

[EDIT] as a workaround I'm putting a special key into Info.plist for simulator builds but it just doesn't feel right.. Another thing would probably be checkin for the path of mainBundle since on device that should be in /Applications and not /Users/....

squidpunch commented 9 years ago

yeah I doubt its by accident - i hope that means you can actually use healthkit and push messages on the simulator while building - would save me about a million hours or so...

GantMan commented 9 years ago

@squidpunch I use this for analytics software, so I don't pollute my analytics with events that occur in development and tests.

A quick fix, is to set an environment variable on your dev machine, and only do X if that that ENV exists. Not a scalable solution. I have ambitions to move the rails figaro gem to rubymotion, and in doing so I could set a flag in there, rather than in RMQ that would be reliable.

Thoughts?

HealsCodes commented 9 years ago

One suggestion I just came up with while browsing motion_print:

@_simulator = !(UIDevice.currentDevice.model =~ /simulator/i).nil? || !!defined?(MotionRepl) if @_simulator.nil?

Never mind.. MotionRepl is only defined after the REPL is active and that's to late. However I had success with this one:

@_simulator = !(NSBundle.mainBundle.bundlePath.start_with? '/var/') if @_simulator.nil?
@_simulator
jamonholmgren commented 9 years ago

Looks good to me, @Shirk . PR?

HealsCodes commented 9 years ago

@jamonholmgren - sure, just opened #296 - btw. remarkable spec suite you have there :wink:

patdobyns commented 9 years ago

This is what I am doing but this only works if you are registering for remote notifications.

If register for remote notifications fails with error 3010, you can assume you are running in a simulator.