如何識別實際的touchBar硬件在Mac書中使用obj c代碼可用,以便我可以提供觸摸欄菜單選項。如何識別實際的touchBar硬件在Mac書中使用obj c?
回答
從Apple文檔:
沒有必要,也沒有API,爲您的應用程序,以瞭解是否有可用的觸摸條。無論您的應用程序是否在支持Touch Bar的計算機上運行,您的應用程序的屏幕用戶界面(UI)都會顯示並且行爲方式相同。
要檢查是否觸杆可用(改善UI/UX例如),你應該實現委託並設置一個布爾值,如:
// Declare a class variable
@property (nonatomic, assign) BOOL isTouchBarAvailable;
@available(OSX 10.12.1, *)
// A bellow version can not be installed on a new MacBook.
// Like an iPhone 7 can't have iOS9 installed.
- (NSTouchBar *)makeTouchBar
{
// ... here the code to make the bar
self.isTouchBarAvailable = YES
return touchBar
}
來源:https://developer.apple.com/reference/appkit/nstouchbar?language=objc
如果你想一些控制,你可以使用isAutomaticCustomizeTouchBarMenuItemEnabled
:
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Here we just opt-in for allowing our instance of the
// NSTouchBar class to be customized throughout the app.
if #available(OSX 10.12.2, *) {
NSApplication.shared().isAutomaticCustomizeTouchBarMenuItemEnabled = true
}
}
/*
Whether or not a menu item to customize the touch bar can be automatically
added to the main menu. It will only actually be added when hardware
or simulator is present. Defaults to NO. Setting this property to YES
is the recommended way to add the customization menu item.
*/
@I'L'I我們可以使用OSX版本來識別API支持,假設舊的Mac用戶升級了他們的操作系統,但沒有TouchBar(硬件),我們如何識別。 –
@JebaMoses:沒有具體的方式,我知道,我想你可以返回一個touchBar是否能夠成功返回。否則,根據文檔,實際上沒有API需要處理,因爲無論系統是否具有支持它的硬件,touchBar都可用。 [這裏有一種方法可以檢查返回值...](https://gist.github.com/anonymous/1f8ad96ebcfb4ecfa489ee56ce6df1f6)(Swift)。如果沒有返回,那麼你可以假設沒有touchBar。 –
基本上在'Obj-C'中,你可能會做一些等同於'if(NSTouchBar()== nil)'......老實說,我不知道它是否會起作用。我什麼都沒有返回,但我沒有touchBar來測試它:) –
NSTouchBar可以在軟件工作,以及硬如Xcode中的模擬器所示。它不需要硬件工作。但是,Xcode 8發行說明會告訴您如何測試操作系統是否可以支持任何類型的觸摸欄功能。
https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html
的Xcode 8.1支持觸摸條對於Mac系統,其中包括它,並支持添加觸摸條功能,您的應用程序。 (28859277) 在您的應用程序中使用觸摸欄功能之前,請確認應用程序使用運行時檢查在包含對觸摸欄的支持的macOS版本上運行。
例如,下面的Objective-C代碼執行運行時檢查,以確保NSTouchBar可用:
NSClassFromString(@ 「NSTouchBar」)=零
在斯威夫特代碼,請可用性檢查對於macOS 10.12.1,以及針對Touch Bar類可用性的運行時檢查。例如:
NSClassFromString(「NSTouchBar」)=零
- 1. Obj-C中的圖像識別庫?
- 2. 如何切換使用OBJ-C中的Mac OS 10.6+
- 3. Obj-C controller.view.frame獲取實際大小
- 4. 如何識別SSL中使用的證書的PKCS?
- 5. 如何在GNUstep中使用Obj-C 2.0?
- 6. 如何在Obj中使用屬性C
- 7. C#實際使用
- 8. Xcode如何使用Macbook Pro Touchbar?
- 9. 在Xcode Playgrounds中實現TouchBar功能
- 10. 如何識別使用Win32_DiskDrive的系統硬盤
- 11. 如何在Python中使用SVM實現用於手寫識別的.dat文件
- 12. 如何識別網頁的實際訪問
- 13. Apache無法識別使用Mac的PHP
- 14. 用戶空間中的硬件識別Linux
- 15. 如何識別已刪除的書籤
- 16. 如何使用C#識別CMYK圖像
- 17. 如何識別唯一的Mac系統
- 18. 在C中實際使用extern?
- 19. Android上的硬幣識別
- 20. 如何使用OBJ文件?
- 21. 如何在jQuery中實際使用ZeroClipboard?
- 22. 如何在CGAL中使用.obj文件
- 23. 如何在C#項目中識別未使用的類
- 24. 在Obj中使用NSArray C
- 25. Angular $ http緩存:如何識別緩存響應vs實際$ http.get
- 26. 如何識別使用mac文本語音的流氓程序
- 27. OpenCL抽象和實際硬件
- 28. 如何使用C++獲取文件的實際大小?
- 29. 如何在OBJ C(Xcode中)
- 30. 如何使用圖像在Java中實現人臉識別?
感謝您這樣回答,你能告訴我去訪問可用輸入,用於在Mac /輸出。以便我可以從硬件列表中識別TouchBar是否可用。 –
我正在更新我的答案 – Ludovic
請考慮這種情況:假設舊Mac用戶升級其操作系統但沒有TouchBar(硬件),我們如何識別。 (Bcz我需要在偏好設置中提供一些與觸摸欄有關的選項。) –