我刚刚将Xcode更新到版本10.3(10G8)。
现在,我的项目未运行并出现以下错误:
/* com.apple.actool.errors */
: error: Failed to find a suitable device for the type IBSimDeviceTypeiPad2x (com.apple.dt.Xcode.IBSimDeviceType.iPad-2x) with runtime iOS 12.4 (12.4 - 16G73) - com.apple.CoreSimulator.SimRuntime.iOS-12-4
Failure Reason: Failed to create new simulator device that matches IBSimDeviceTypeiPad2x (com.apple.dt.Xcode.IBSimDeviceType.iPad-2x) for runtime iOS 12.4 (12.4 - 16G73) - com.apple.CoreSimulator.SimRuntime.iOS-12-4 (Invalid runtime: com.apple.CoreSimulator.SimRuntime.iOS-12-4)
Underlying Errors:
Description: Invalid runtime: com.apple.CoreSimulator.SimRuntime.iOS-12-4
/* com.apple.actool.compilation-results */
/Users/xxx/Library/Developer/Xcode/DerivedData/xxxxx-dxlvvymxzdfqjubnuntqlxggtyja/Build/Intermediates.noindex/xxxxx.build/Debug-iphonesimulator/xxxxx.build/assetcatalog_generated_info.plist
Run Code Online (Sandbox Code Playgroud)
所以我的朋友从OneSignal收到了这封电子邮件
由于即将到来的iOS 13版本可能会发生更改,因此在使用Xcode 11构建应用程序之前,必须先更新到最新版本的iOSSDK。OneSignal的所有包装SDK(包括React Native,Unity和Flutter)都已经过也更新了。原因是与iOS 13一起发布的Xcode 11打破了OneSignal之类的应用程序和库用于获取设备推送令牌的通用技术。如果您不使用我们的新SDK,那么新用户将无法从您的应用订阅通知。
我对此感到好奇。
这是我们在iOS 12上获取设备通知令牌的方式
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
var token = ""
for i in 0..<deviceToken.count {
token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])
}
print("Notification token = \(token)")
}
Run Code Online (Sandbox Code Playgroud)
在iOS 13上获取它的正确方法是什么?我应该为当前开发的应用程序采用新方法还是旧方法仍然可行?
我知道我可以使用以下代码更改 SwiftUI 中的视图背景颜色:
.background(Color(.systemGroupedBackground))
Run Code Online (Sandbox Code Playgroud)
但是我不能为小部件背景颜色本身做到这一点!
我使用这个代码:
struct XWidget: Widget { // MARK: Widget is defined here
var body: some WidgetConfiguration {
StaticConfiguration(
kind: "xWidget",
provider: xProvider(),
placeholder: Text("Loading...")) { entry in
xWidgetEntryView(entry: entry).background(Color(.systemGroupedBackground)) // <= here
}.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
}
}
Run Code Online (Sandbox Code Playgroud)
但结果是这样的:
所以我想检查我是否有权访问 iOS14 上的用户位置&我找到了这段代码,但 XCode(12) 对我大喊大叫:
'authorizationStatus()' was deprecated in iOS 14.0
Run Code Online (Sandbox Code Playgroud)
这是代码:
func hasLocationPermission() -> Bool {
var hasPermission = false
if CLLocationManager.locationServicesEnabled() {
switch CLLocationManager.authorizationStatus() { // <= 'authorizationStatus()' was deprecated in iOS 14.0
case .notDetermined, .restricted, .denied:
hasPermission = false
case .authorizedAlways, .authorizedWhenInUse:
hasPermission = true
@unknown default:
hasPermission = false
}
} else {
hasPermission = false
}
return hasPermission
}
Run Code Online (Sandbox Code Playgroud)
那么我应该用什么来代替呢?
我使用此代码来检查我是否有权访问用户位置
if CLLocationManager.locationServicesEnabled() {
switch CLLocationManager.authorizationStatus() {
case .restricted, .denied:
hasPermission = false
default:
hasPermission = true
}
} else {
print("Location services are not enabled")
}
}
Run Code Online (Sandbox Code Playgroud)
Xcode(12) 用这个警告对我大喊大叫:
'authorizationStatus()' was deprecated in iOS 14.0
Run Code Online (Sandbox Code Playgroud)
那么什么是替代品呢?
如何从我的应用程序上的Apple Watch状态栏屏幕隐藏或删除小时钟?
我在网上搜索了这个,但一无所获!
我刚刚发现,如果你删除那个时钟,Apple会拒绝你的应用程序,但我的应用程序本身就是一个表盘而且不需要显示那个时间.
我从这里得到了这个 mac 屏幕保护程序示例。
我将其更改为显示图像而不是 textField。
问题是:它可以显示任何 Xcode 对象,例如 textView。textField、Button 等...但它无法在 imageView 上加载图像。(它可以在 Xcode 调试版本上加载图像,但不能在 mac 屏幕保护程序上的发布版本上加载图像)
发布构建截图
这是我显示图像的代码:
let imageView = NSImageView(frame: self.frame)
imageView.image = NSImage(named: "Image")
imageView.layer?.backgroundColor = NSColor.red.cgColor
imageView.backgroundColor(.red)
addSubview(imageView)
DispatchQueue.main.async {
imageView.frame = CGRect(x: 100, y: 100, width: 200, height: 100)
self.setNeedsDisplay(imageView.frame)
}
Run Code Online (Sandbox Code Playgroud)
我很确定它无法访问图像文件,但我该如何解决这个问题?实际上,屏幕保护程序的行为非常奇怪,当我在 ImageView 之后添加另一个 UI 元素时,它们都没有显示在屏幕上。
macOS 屏幕保护程序有什么问题?(我从一些网站下载了一些第三方屏幕保护程序,它们也是黑屏。)
我想为 iOS 13+ 自定义上下文菜单上的操作按钮
菜单是这样的:
我想我可以像 UIAlertController 操作一样设置自定义字体,如下所示:
let action = UIAction(title: "asdasd") { _ in}
let attributeString = NSMutableAttributedString(string: action.title)
attributeString.addAttributes([NSAttributedString.Key.font : font], range: NSMakeRange(0, action.title.count))
action.setValue(attributeString, forKey: "attributedMessage")
Run Code Online (Sandbox Code Playgroud)
但它不是这样工作的,那是怎么回事呢?
在 iOS 13 上,我们为 tableView 和 collectionView 提供了漂亮的上下文菜单。
我在 UICollectionView 上使用它,如下所示:
'cellForItemAt indexPath' 上的实现:
let interaction = UIContextMenuInteraction(delegate: self)
cell.moreButton.isUserInteractionEnabled = false
cell.moreButton.tag = indexPath.row
cell.addInteraction(interaction)
Run Code Online (Sandbox Code Playgroud)
在“configurationForMenuAtLocation 位置”上处理老虎
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { suggestedActions in
var actions = [UIAction]()
for item in self.contextMenuItems {
let action = UIAction(title: item.title, image: item.image, identifier: nil, discoverabilityTitle: nil) { _ in
self.didSelectContextMenu(index: 0) <== how pass the index from here? …
Run Code Online (Sandbox Code Playgroud) 我目前正在使用 Swift (macOS),这没关系。
我可以使用来自 Firestore 的这个简单的 get 请求来获取我的数据库数据
https://firestore.googleapis.com/v1beta1/projects/MY_PROJECT_NAME/databases/(default)/documents/" + "User_email" + "?pageSize=100&pageToken=" + "NextPage_Id"
Run Code Online (Sandbox Code Playgroud)
现在我想更新数据库上的一个文件,我不知道如何。
Firebase api 指南对我来说太复杂了,我不明白。
我发现这个获取请求网址:
https://firestore.googleapis.com/v1beta1/projects/{projectId}/databases/{databaseId}/documents/{document_path}?updateMask.fieldPaths=status&updateMask.fieldPaths=title
Run Code Online (Sandbox Code Playgroud)
但是当我尝试时,它给了我这个错误:
{
"details" : [
{
"fieldViolations" : [
{
"description" : "Invalid JSON payload received. Unknown name \"updateMask.fieldPaths\": Cannot bind query parameter. Field 'updateMask' could not be found in request message."
}
],
"@type" : "type.googleapis.com\/google.rpc.BadRequest"
}
],
"code" : 400,
"message" : "Invalid JSON payload received. Unknown name \"updateMask.fieldPaths\": Cannot bind query parameter. Field 'updateMask' could not …
Run Code Online (Sandbox Code Playgroud) swift ×5
ios13 ×3
contextmenu ×2
ios ×2
ios14 ×2
xcode ×2
api ×1
apple-watch ×1
custom-font ×1
fonts ×1
location ×1
macos ×1
screensaver ×1
storyboard ×1
swiftui ×1
watchkit ×1
watchos ×1
web ×1
widget ×1
xcode11 ×1