通过 Cocoapods 和桥接头使用 Pinterest 的 iOS SDK,在我的应用程序中运行良好。
在我的项目中创建了新的目标 -> 操作扩展。尝试在链接框架和库中链接 PDK 框架,尝试在扩展中添加单独的桥接头文件,但 Xcode 崩溃无法找到它......关于如何导入它的任何想法?
播客文件:
platform :ios, '9.0'
pod "PinterestSDK", :git => "git@github.com:pinterest/ios-pdk.git"
pod "PINRemoteImage"
pod "GBDeviceInfo"
pod 'FBSDKCoreKit'
xcodeproj '/Users/garysabo/Dropbox/Xcode Projects/pinFixer2/pinFixer2.xcodeproj'
Run Code Online (Sandbox Code Playgroud)
桥接头:
#import "PinterestSDK.h"
#import "PDKPin.h"
#import "PDKBoard.h"
#import "PDKImageInfo.h"
#import "PDKResponseObject.h"
#import "PDKClient.h"
#import "PDKModelObject.h"
#import "PDKUser.h"
Run Code Online (Sandbox Code Playgroud) 由于我在SpriteKit工作,我的按钮是SKSpriteNodes...但是我发现自己处于需要将焦点设置在我的viewController覆盖范围内的情况preferredFocusedView.有没有办法将一个转发SKSpriteNode为一个UIView?如果是这样的话,我还没弄清楚......还有其他选择吗?
let playButton = SKSpriteNode(imageNamed: "PlayButton")
playButton.position = CGPoint(x: scene.size.width * 0.25, y: scene.size.height * 0.25)
playButton.zPosition = Layer.UI.rawValue
scene.worldNode.addChild(playButton)
override var preferredFocusedView: UIView? {
get {
return //playButton how?
}
}
Run Code Online (Sandbox Code Playgroud) 我使用的是Pinterest的SDK下载Pinterest的引脚的连接,(样品链接,我从服务器返回: https://www.pinterest.com/r/pin/186195765822871832/4801566892554728205/77314e40aeb26c0dc412e9cfa82f8dccc401fdb2b9806a3fe17ba8bafdb50510)。
大约 5 天前,当我尝试访问从 Pinterest 拉下的类似链接时,我的 NSURLSession 中开始出现 404 错误。
一位朋友说,他认为 Pinterest 现在必须要求使用 cookie 才能访问该链接。
如何配置我的会话,以便我可以使用 cookie 并从 Pinterest 获得 200 响应?
更新代码:
import UIKit
import PlaygroundSupport
var url = URL(string: "https://www.pinterest.com/r/pin/186195765822871832/4801566892554728205/77314e40aeb26c0dc412e9cfa82f8dccc401fdb2b9806a3fe17ba8bafdb50510")
var getSourceURLFromPinterest: URLSessionDataTask? = nil
let sessionConfig: URLSessionConfiguration = URLSessionConfiguration.default
sessionConfig.timeoutIntervalForRequest = 30.0
sessionConfig.timeoutIntervalForResource = 30.0
let cookieJar = HTTPCookieStorage.shared
let cookieHeaderField = ["Set-Cookie": "key=value, key2=value2"]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: cookieHeaderField, for: url!)
HTTPCookieStorage.shared.setCookies(cookies, for: url, mainDocumentURL: url)
let session = URLSession(configuration: sessionConfig)
getSourceURLFromPinterest = session.dataTask(with: …Run Code Online (Sandbox Code Playgroud) 我在网上找不到任何文档来解释如何添加 Watch Series 4 上提供的任何新的“图形”复杂功能。以下是我的步骤:
(1) 添加符合的类CLKComplicationDataSource(下面的代码) (2) 将并发症配置设置为指向 (1) 和 Complications asset 文件夹
(4) 从 Sketch 导出 png 并拖动到 Complications 资源文件夹中,以使用 Complications 资源文件夹中的模块化/实用/圆形图形(角、边框和圆形)占位符,该占位符不接受 png(仅限 pdf)。
毕竟,旧的模块化实用和圆形复杂功能工作正常,但是图形(角、边框和圆形)的图像(pdf)不会在设备上呈现
import Foundation
import ClockKit
class HockeyTrackerComplication: NSObject, CLKComplicationDataSource {
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
handler([])
}
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
if #available(watchOSApplicationExtension 5.0, *) {
if complication.family == .circularSmall {
let template = CLKComplicationTemplateCircularSmallRingImage()
guard let image = …Run Code Online (Sandbox Code Playgroud) 下面的代码正在工作(onAppear 被调用)但是一旦我将我的两个视图嵌套在一个 tabView 中(以呈现类似 UIPageViewController 的 UI),第二个视图的 onAppear 函数就永远不会被调用,这是一个错误还是我在做什么做错了吗?
struct SetUpWorkoutView: View {
var body: some View {
NavigationView {
List {
ForEach(sessionTypes) { sessionType in
NavigationLink(destination: LiveWorkoutView(sessionType: sessionType)) {
SessionTypeRow(name: sessionType.stringValue)
}
}
}
}
struct LiveWorkoutView: View {
var body: some View {
VStack(alignment: .leading) { }
}.onAppear(perform: {
print("on appear called in LiveWorkoutView")
}
}
}
}
@main
struct SwiftUITestApp: App {
var body: some Scene {
WindowGroup {
TabView {
SetUpWorkoutView()
WatchSettingsView()
}
.tabViewStyle(PageTabViewStyle())
}
} …Run Code Online (Sandbox Code Playgroud) 我想移植我现有的 UIKit 应用程序以使用适用App于 iOS 14 的新 API。(但仍然使用AppDelegatevia 的方法UIApplicationDelegateAdaptor,但是我仍然想支持 iOS 13。有没有一种方法可以设置,以便 iOS 14 ,使用Appas@main但如果 iOS 13 使用AppDelegateas @UIApplicationMain?即使下面的代码也无法编译,因为我的最低构建目标是 iOS 13:
@available(iOS 14.0, *)
@main
struct HockeyTrackerApp: App {
// inject into SwiftUI life-cycle via adaptor !!!
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
HomeView()
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图在userDidAcceptCloudKitShareWith被调用时得到通知。传统上这是在 中调用的,App Delegate但是因为我正在构建一个 iOS 14+App用作我的根对象。关于如何添加userDidAcceptCloudKitShareWith到我的 App 类,我还没有找到任何文档,所以我正在UIApplicationDelegateAdaptor使用一个App Delegate类,但是它似乎userDidAcceptCloudKitShareWith从来没有被调用过?
import SwiftUI
import CloudKit
// Our observable object class
class ShareDataStore: ObservableObject {
static let shared = ShareDataStore()
@Published var didRecieveShare = false
@Published var shareInfo = ""
}
@main
struct SocialTestAppApp: App {
@StateObject var shareDataStore = ShareDataStore.shared
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView().environmentObject(shareDataStore)
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 SwiftUI Lazy Grid 来布局具有不同长度字符串的视图。我如何构建我的代码,例如,如果 3 个视图不适合,它只会生成 2 列并将第三个视图推到下一行,以便它们不会重叠?
struct ContentView: View {
var data = [
"Beatles",
"Pearl Jam",
"REM",
"Guns n Roses",
"Red Hot Chili Peppers",
"No Doubt",
"Nirvana",
"Tom Petty and the Heart Breakers",
"The Eagles"
]
var columns: [GridItem] = [
GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible())
]
var body: some View {
LazyVGrid(columns: columns, alignment: .center) {
ForEach(data, id: \.self) { bandName in
Text(bandName)
.fixedSize(horizontal: true, vertical: false)
}
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static …Run Code Online (Sandbox Code Playgroud) 我可以读出HKworkout并添加我自己的元数据,然后重新保存吗?如果是这样怎么办?或者我可以只在保存锻炼时传递元数据吗?
我在控制台中看到此错误,不确定是什么原因?我一次请求用户位置。
2018-09-12 20:04:26.912292-0400 Watch Extension[40984:3250895] [Client] Failure to deallocate CLLocationManager on the same runloop as its creation may result in a crash
代码如下:
import CoreLocation
class WorkoutLocationManager: NSObject, CLLocationManagerDelegate {
private var locationManager: CLLocationManager?
public var formattedWorkoutAddress: String?
public func getWorkoutLocation() {
guard CLLocationManager.locationServicesEnabled() else {
print("User does not have location services enabled")
return
}
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
let locationAuthorizationStatus = CLLocationManager.authorizationStatus()
switch locationAuthorizationStatus {
case .authorizedAlways:
print("location authorized Always")
locationManager?.requestLocation()
case .authorizedWhenInUse:
print("location …Run Code Online (Sandbox Code Playgroud) swift ×10
ios ×8
swiftui ×4
xcode ×2
appdelegate ×1
apple-watch ×1
cloudkit ×1
cocoapods ×1
frameworks ×1
healthkit ×1
icloud ×1
lazyvgrid ×1
nsurlsession ×1
onappear ×1
tabview ×1
tvos ×1
watchos ×1