我检查了我的配置文件,一切都很好,因为我在firebase提供的演示中使用了配置文件,我正在接收来自该演示项目的推送通知.问题是在我使用的主要项目中:
我仍然无法在我的项目中收到推送通知.让我知道我在哪里错过了什么.
我正在进行三个 api 调用,并希望 API1 应首先执行,完成后应执行 API2,然后执行 API3。我为此使用了操作队列,并添加了对操作的依赖性。我也尝试设置优先级,但没有按顺序获取 api 调用。帮我看看如何正确制作。
代码是这样的:
let op1 = Operation()
op1.completionBlock = {
self.APICall(urlString: self.url1)
}
op1.queuePriority = .veryHigh
let op2 = Operation()
op2.completionBlock = {
self.APICall(urlString: self.url2)
}
op2.queuePriority = .high
let op3 = Operation()
op3.completionBlock = {
self.APICall(urlString: self.url3)
}
op3.queuePriority = .normal
op2.addDependency(op1)
op3.addDependency(op2)
queue.addOperations([op1, op2, op3], waitUntilFinished: false)
Run Code Online (Sandbox Code Playgroud)
我将 API 调用方法放在 DispatchQueue.main.sync 中,如下所示:
func APICall(urlString: String) {
let headers: HTTPHeaders = [
"Accept": "text/html"
]
print(urlString)
DispatchQueue.main.sync {
Alamofire.request(urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!, method: .get, …Run Code Online (Sandbox Code Playgroud) 我想ViewController在 Swift 4 中呈现一个as popover,但它Viewcontroller通常呈现,这是代码:
class CustomTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let favViewController = TrialViewController()
let exhibtionViewController = TrialViewController()
let menuViewController = ttttViewController()
let notificationViewController = TrialViewController()
let profileViewController = ttttViewController()
favViewController.tabBarItem.title = "first"
exhibtionViewController.tabBarItem.title = "second"
menuViewController.tabBarItem.title = "third"
notificationViewController.tabBarItem.title = "forth"
profileViewController.tabBarItem.title = "fifth"
favViewController.tabBarItem.image = UIImage(named:"home25")
exhibtionViewController.tabBarItem.image = UIImage(named: "bag25")
menuViewController.tabBarItem.image = UIImage(named: "main_add_25")
notificationViewController.tabBarItem.image = UIImage(named: "notification25")
profileViewController.tabBarItem.image = UIImage(named: "man_man25")
let tabBarItemWidth = Int(self.tabBar.frame.size.width) / (self.tabBar.items?.count)!
let x …Run Code Online (Sandbox Code Playgroud) 如何仅设置 UILabel 文本属性一次,然后仅更改文本(字符串)
mTextValue.attributedText = NSAttributedString(string: "STRING",
attributes:
[NSAttributedStringKey.strokeWidth: -3.0,
NSAttributedStringKey.strokeColor: UIColor.black])
mTextValue.text = "NEW STRING" // won't change anything
Run Code Online (Sandbox Code Playgroud)
或者要设置新字符串,我必须一次又一次地NSAttributedString设置吗?.attributedText
根据 Place Autocomplete 文档,预测数组的对象没有位置信息。那么我应该如何获取经度和纬度的详细信息。下面是我的代码 -
extension ViewController: GMSAutocompleteFetcherDelegate {
func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {
tableData.removeAll()
for prediction in predictions{
tableData.append(prediction.attributedFullText.string)
}
locationTable.reloadData()
}
func didFailAutocompleteWithError(_ error: Error) {
print(error.localizedDescription)
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在UserDefaults中存储字典,并且在代码运行时总是让应用程序崩溃.以下是在执行应用程序时崩溃应用程序的示例代码.我试图将它作为NSDictionary投射或最初使其成为NSDictionary - 得到相同的结果.
class CourseVC: UIViewController {
let test = [1:"me"]
override func viewDidLoad() {
super.viewDidLoad()
defaults.set(test, forKey: "dict1")
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试裁剪 NSImage 的选定部分,该部分按照 ProportionallyUpOrDown(AspectFill) 模式安装。我正在使用鼠标拖动事件绘制一个框架,如下所示:
class CropImageView: NSImageView {
var startPoint: NSPoint!
var shapeLayer: CAShapeLayer!
var flagCheck = false
var finalPoint: NSPoint!
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
}
override var image: NSImage? {
set {
self.layer = CALayer()
self.layer?.contentsGravity = kCAGravityResizeAspectFill
self.layer?.contents = newValue
self.wantsLayer = true
super.image = newValue
}
get {
return super.image
}
}
override func mouseDown(with event: NSEvent) { …Run Code Online (Sandbox Code Playgroud) 我在静态表视图中有 UITextView ,如果用户触摸textView 之外的其他区域,我想移除键盘
通常我可以用这行代码来移除键盘,但我不知道为什么,在 textview 中添加占位符后,它不起作用。我怀疑是因为它在静态表视图中
extension CheckinDetailTVC {
// to remove keyboard if we touch other area
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(false)
}
}
Run Code Online (Sandbox Code Playgroud)
我也在 stackoverflow 中尝试了另一种解决方案,但没有人在我身上工作,比如添加手势识别器
override func viewDidLoad() {
super.viewDidLoad()
let tapGestureReconizer = UITapGestureRecognizer(target: self, action: "tap:")
view.addGestureRecognizer(tapGestureReconizer)
}
func tap(sender: UITapGestureRecognizer) {
view.endEditing(true)
}
Run Code Online (Sandbox Code Playgroud)
或在 TextViewDelegate 中添加函数,但它也不起作用
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
if text == "\n" {
textView.resignFirstResponder()
} …Run Code Online (Sandbox Code Playgroud) 确定枚举类型数组是否包含特定枚举类型的最佳方法是什么,最重要的是枚举案例具有关联类型
例如,使用以下数据结构,我将如何获得第一个视频
let sections = [OnDemandSectionViewModel]
public struct OnDemandSectionViewModel: AutoEquatable {
public let sectionStyle: SectionHeaderStyle
public let sectionItems: [OnDemandItemType]
public let sectionType: SectionType
}
public enum OnDemandItemType: AutoEquatable {
case video(VideoViewModel)
case button(ButtonViewModel)
case game(GameViewModel)
case collectionGroup(CollectionGroupViewModel)
case clip(ClipViewModel)
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试找到第一个视频,目前,我正在执行以下操作,但是很好奇是否有更好的方法
for section in sections {
for item in section.sectionItems {
switch item {
case .video(let video):
print("This is the first video \(video)")
return
default: break
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个MainCollectionView用于在项目之间滚动,在这些单元格之一的内部,我还有一个带有单元格的collectionView。在该集合视图中,每个单元格都有一个按钮。我的问题是在点击时如何将按钮的动作传递给MainCollectionView?我确实在单元格中为该按钮创建了协议,但是我不知道如何在点击按钮时让MainCollectionView知道。我可以从单元格类中调用动作,但我认为最好在作为MainCollectionView的Model中运行它。以下是我的按钮协议。
protocol ThanhCaHotTracksCellDelegate: class {
func handleSeeAllPressed()}
weak var delegate: ThanhCaHotTracksCellDelegate?
@objc func handleSeeAllButton(){
delegate?.handleSeeAllPressed()
}
Run Code Online (Sandbox Code Playgroud) ios ×9
swift ×9
crop ×1
enums ×1
google-maps ×1
macos ×1
nsimage ×1
queue ×1
swift4 ×1
uikit ×1
uilabel ×1
uitabbar ×1
uitableview ×1
uitextview ×1