Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iPhone X not being detected #35

Closed
asaxionis opened this issue Oct 4, 2017 · 4 comments
Closed

iPhone X not being detected #35

asaxionis opened this issue Oct 4, 2017 · 4 comments

Comments

@asaxionis
Copy link

asaxionis commented Oct 4, 2017

I am currently trying to determine if the phone being used is an iPhone x within a collectionview & when i run the iPhone X in the simulator, it running the default code rather than the iPhoneX code, any idea as to why this is happening? Here is the code.

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        let deviceType = UIDevice.current.deviceType
        
        switch deviceType {
        case .iPhoneX:
print("is this the iPhone x?")
            if index == 1 || index == 3 {
                width = (collectionView.bounds.width)
            } else {
                width = (collectionView.bounds.width) / 5
            }
        default:

            if index == 1 || index == 3 {
print("this is not the iphone x")
                width = (collectionView.bounds.height)
            } else {
                width = (collectionView.bounds.height) / 3
            }
            
            
        }
        
        return CGSize(width:width, height:width)
    }

So it appears that there is a separate device for the simulator, how exactly am I supposed to test code on an iPhone X if this is unable to detect the simulator type?

@igorkislyuk
Copy link
Collaborator

Hi. You are really cannot detect simulator type, but you can adjust collection size according to display screen size. There is no really need to know if this is X or SE, for example.

@eligreenfeld
Copy link

@igorkislyuk It seems that you can get simulator type:
ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"]

@igorkislyuk
Copy link
Collaborator

@eligreenfeld Yes, you're right. Feel free to add this functionality.

@kudit
Copy link

kudit commented Mar 21, 2024

This functionality is present in this project: GitHub.com/kudit/Device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants