2

有没有办法确定运行 iOS TodayExtension 的设备的设备类型。我无法在 Swift 中做到这一点。

我需要有这样的东西:

-(BOOL)isiPad {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return YES;
    } else {
        return NO;
    }
}

但在 Swift 和 TodayExtension 中。

编辑:

let IS_IPAD = (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad);

在 iOS TodayExtensions 中不起作用。

在此处输入图像描述

4

4 回答 4

9

在 Swift 中,您可以使用此代码。

let isiPad: Bool = (UIDevice.currentDevice().userInterfaceIdiom == .Pad);

在我看来,将此用作常数。

if (isiPad) {
    println(isiPad)
} 
else {
    println(isiPad)
}
于 2015-04-28T12:06:35.913 回答
2

斯威夫特 4

UIDevice.current.userInterfaceIdiom == .pad

于 2018-04-10T13:45:41.800 回答
0

斯威夫特 5

您始终可以使用扩展程序直接访问您的完整应用程序:

import UIKit

extension Bool {

    static let isiPad = UIDevice.current.userInterfaceIdiom == .pad
}

然后,只需在任何地方使用这样的东西

if .isiPad { your logic here }
于 2021-03-10T07:22:16.620 回答
-6

我只是自己想通了。这是代码...

let iPad: [CGFloat]! = [2048, 1024]
let iPhone: [CGFloat]! = [1920, 1334, 1136]

func isIpad() -> Bool {
    if (find(iPad, UIScreen.mainScreen().bounds.height) != nil) {
        return true
    } else {
        return false
    }
}
于 2014-09-13T21:47:06.600 回答