Quali sono tutti i valori possibili restituiti da [[UIDevice currentDevice] model];
? Non è documented.UIDevice currentDevice model values values
risposta
Le possibili valli sono iPod touch
, iPhone
, iPhone Simulator
, iPad
, iPad Simulator
Se volete sapere quale hardware iOS
sta rovinando avanti così iPhone3
, iPhone4
, iPhone5
ecc sotto è il codice per quella
NOTA: Il seguente codice potrebbe non contenere tutti devi stringa di ce, sto con gli altri ragazzi stanno mantenendo lo stesso codice su GitHub quindi si prega di prendere l'ultimo codice da lì
Objective-C: GitHub/DeviceUtil
Swift: GitHub/DeviceGuru
#include <sys/types.h>
#include <sys/sysctl.h>
- (NSString*)hardwareDescription {
NSString *hardware = [self hardwareString];
if ([hardware isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";
if ([hardware isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([hardware isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
if ([hardware isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
if ([hardware isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
if ([hardware isEqualToString:@"iPod1,1"]) return @"iPodTouch 1G";
if ([hardware isEqualToString:@"iPod2,1"]) return @"iPodTouch 2G";
if ([hardware isEqualToString:@"iPad1,1"]) return @"iPad";
if ([hardware isEqualToString:@"iPad2,6"]) return @"iPad Mini";
if ([hardware isEqualToString:@"iPad4,1"]) return @"iPad Air WIFI";
//there are lots of other strings too, checkout the github repo
//link is given at the top of this answer
if ([hardware isEqualToString:@"i386"]) return @"Simulator";
if ([hardware isEqualToString:@"x86_64"]) return @"Simulator";
return nil;
}
- (NSString*)hardwareString {
size_t size = 100;
char *hw_machine = malloc(size);
int name[] = {CTL_HW,HW_MACHINE};
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
free(hw_machine);
return hardware;
}
Ho appena effettuato un test su iPod Touch, iPhone, Retina telefono, iPhone 5, iPad, Retina iPad e Mini iPad. Quindi questa è la mia conclusione:
iPod touch
iPhone
iPad
su simulatori - questo potrebbe essere utile se sei uno sviluppatore che lavora sulle caratteristiche che a volte non funzionano affatto su simulatori - si otterrà questi valori:
iPhone Simulator
iPad Simulator
Hai dimenticato i simulatori ... – andreas
Ah, la risposta effettiva alla domanda postata! Grazie. Mi chiedevo specificamente se l'iPad Mini sarebbe stato indicato e non ne avesse uno a portata di mano (e non è supportato nel simulatore XCode), e questo ha risposto. – BobDickinson
Qualcuno conosce i valori di AppleTV? – ColdLogic
Credo che la migliore risposta da spiegare (qualcosa che non è stato scritto qui) È dire che il valore stesso è un valore di stringa. e le possibili risposte sono stringhe ad esempio: "iPhone", "iPad" ed ecc.
Nessuna di queste risposte è estendibile per i nuovi numeri di modello. Qui è un'enumerazione:
public enum DeviceType {
case iPad(String?)
case iPhone(String?)
case simulator(String?)
case appleTV(String?)
case unknown
}
e l'estensione ho scritto che secondo me è un po 'più pulito e un po' più estensibile per quando il numero nuovo modello di venire fuori.
extension UIDevice {
public static func getDevice() -> DeviceType {
var info = utsname()
uname(&info)
let machineMirror = Mirror(reflecting: info.machine)
let code = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else {
return identifier
}
return identifier + String(UnicodeScalar(UInt8(value)))
}
if code.lowercased().range(of: "ipad") != nil {
if let range = code.lowercased().range(of: "ipad") {
var mutate = code
mutate.removeSubrange(range)
return .iPad(mutate)
}else{
return .iPad(nil)
}
}else if code.lowercased().range(of: "iphone") != nil {
if let range = code.lowercased().range(of: "iphone") {
var mutate = code
mutate.removeSubrange(range)
return .iPhone(mutate)
}else{
return .iPhone(nil)
}
}else if code.lowercased().range(of: "i386") != nil || code.lowercased().range(of: "x86_64") != nil{
return .simulator(code)
}else if code.lowercased().range(of: "appletv") != nil {
if let range = code.lowercased().range(of: "appletv") {
var mutate = code
mutate.removeSubrange(range)
return .appleTV(mutate)
}else{
return .appleTV(nil)
}
}else{
return .unknown
}
}
}
- 1. Hidden Markov Model Multiple Observation values per ogni stato
- 2. Laravel Form-Model Binding multi select default values
- 3. [UIDevice currentDevice] .orientation == UIDeviceOrientationUnknown seguente UINavigationController spingere
- 4. matplotlib get ylim values
- 5. Android setText/R.string/values
- 6. Generazione Comma Separated Values
- 7. MySQL Comma Separated Values
- 8. React, Binding input values
- 9. Django: using values () e get_FOO_display()?
- 10. Extract -webkit-transform matrix3d values
- 11. Hibernate database specifica columnDefinition values
- 12. SQL: INSERT INTO ... VALUES..SELECT
- 13. Django ORM - mock values (). Filter() chain
- 14. Come posso avere res/values-pt_PT e res/values-pt_BR su Android?
- 15. Che cosa si intende per le cartelle values-v11 e values-v14?
- 16. . NET SortedDictionary But Sorted By Values
- 17. Stampa p-values con <0,001
- 18. Quando utilizzare (valori ...) (define-values ...) in Schema
- 19. UIDevice Orientation
- 20. Come ottenere Json Post Values con asp.net webapi
- 21. Gestione delle colonne Identity in un'istruzione "Insert Into TABLE Values ()"?
- 22. Errore nel file values-23 generato in Android
- 23. Lazy load values in datatable impaginato usando jquery
- 24. Come si trasforma un array PHP in $ keys e $ values?
- 25. Enum.valueOf bug con JDK 7 SE dove .values () viene danneggiato
- 26. boost :: asio :: deadline_timer con std :: chrono time values
- 27. Accedere al metodo .values () e .ordinal() di enum arbitrario?
- 28. C'è un modo per sovrascrivere strings.xml in res/values?
- 29. Il valore Enum # values () assegna memoria ad ogni chiamata?
- 30. MySQL INSERT INTO table VALUES .. vs INSERT INTO table SET
Sono curioso perché è stato accettato. Non risponde affatto alla domanda. – rmaddy
Mi sembra come se fosse, ma in modo indiretto. – tomasmcguinness
@Inder Kumar Rathore, in iOS 6.1 questa funzione non funziona perfettamente. In 1 caso da 3, quindi è possibile restituire un altro valore – CReaTuS