Forum iPhone, iPod et iPad, Apple TV, Apple Watch et Mac en français par iPhoneSoft pour les systèmes iOS, macOS, tvOS et watchOS
Vous n'êtes pas identifié(e).
Comment faire une application universelle sans savoir quel est le device qui fait tourner l'application ?
Alors voici une petite astuce pour faire des constantes utilisables à tous moment
//Ajoutez ses constantes dans le .h de votre AppDelegate
#define DEVICE_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // iPad
#define DEVICE_IPHONE_IPOD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) // iPhone ou iPod touch.
#define ORIENTATION_INTERFACE_PORTRAIT (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) // Portrait
#define ORIENTATION_INTERFACE_LANDSCAPE (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) // Paysage
#define ORIENTATION_DEVICE_PORTRAIT (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) // Portrait
#define ORIENTATION_DEVICE_LANDSCAPE (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) // Paysage
#define ORIENTATION_DEVICE_VALID (UIDeviceOrientationIsValidInterfaceOrientation([[UIDevice currentDevice] orientation])) // A plat (marche pour l'iPad seulement)
//Ensuite vous pourrez tester facilement le device dans votre code
if(DEVICE_IPAD) NSLog(@"Je suis un iPad");
if(DEVICE_IPHONE_IPOD) NSLog(@"Je suis un iPhone");
Fondateur & Expert Mobile
iPhoneSoft : Actu Apple
iPhoneTweak : Jailbreak et Cydia
Hors ligne