如何重构NSDictionaries的对象

在我的debugging器中,这是我的日志语句如何打印我的消息对象: self.messages = ( "<lean: 0x7fcf98665140, objectId: vglE1UJ5KI, localId: (null)> {\n messageBody = Jj;\n recipientId = XvvxETqjph;\n senderId = XvvxETqjph;\n timestamp = \"1424991590106.210938\";\n}", "<lean: 0x7fcf98667940, objectId: rgBFYBMKlU, localId: (null)> {\n messageBody = \"test 3 from ian\";\n recipientId = XvvxETqjph;\n senderId = Hoy7UjLzOh;\n timestamp = \"1424631667110.638184\";\n}", "<lean: 0x7fcf98667f30, objectId: hB5uhwsYsu, localId: (null)> {\n messageBody = \"test […]

在许多VC中使用活动指示器,而不需要快速复制代码

我有两个ViewControllers (A和B)在迅速IOS。 A和B都从互联网(分别)加载数据。 我想在加载时显示activityIndicator 。 我知道我可以通过在每个VC中声明一次来做到这一点,如下所示 ViewController A var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView() func activityIndicatorBegin() { activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0,0,50,50)) activityIndicator.center = self.view.center activityIndicator.hidesWhenStopped = true activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray view.addSubview(activityIndicator) activityIndicator.startAnimating() disableUserInteraction() greyView = UIView() greyView.frame = CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height) greyView.backgroundColor = UIColor.blackColor() greyView.alpha = 0.5 self.view.addSubview(greyView) } func activityIndicatorEnd() { self.activityIndicator.stopAnimating() enableUserInteraction() self.greyView.removeFromSuperview() […]

如何收集使用NSDictionary嵌套在数组中的JSON数据

我有以下JSON: { 0: 200, error: false, campaigns: { current_campaigns: [ { id: "1150", campaign_type_id: "1", campaign_type: "Type", title: "Name (with type) ", url: "http://www.example.com", special: null, campaign_instructions: "Here's what you do", pay_description: "", start: "2013-10-14 00:00:00", end: "2014-03-31 23:59:59" }, { id: "1151", campaign_type_id: "1", campaign_type: "Type", title: "Name (with type) ", url: "http://www.example.com", special: […]

将其添加到地图时使用自定义注释

在将其添加到mapview时,我无法访问自定义注记类。 我有自定义类正常工作,但我当我把它添加到地图我不知道如何通过这个委托访问自定义注释: – (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 我试过在网上找,没有find任何东西。 任何帮助将是伟大的。 它被这样调用: CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(shops.latitude, shops.longitude); AnnotationForId *shop = [[AnnotationForId alloc] initWithCoordinate:coords]; //[[CLLocationCoordinate2DMake(shops.latitude, shops.longtitude)]]; shop.title = shops.name; shop.subtitle = @"Coffee Shop"; shop.shopId = shops.id; [map addAnnotation:shop];

相同的应用名称,但不同的国家和二进制

我有一个应用程序的版本,目前在墨西哥商店可用,但我想做一个哥伦比亚版本。 使用的数据和用户界面会有所变化。 我可以创build一个不同的二进制file upload到不同的商店,仍然保持相同的应用程序名称? 我发现上面的问题没有答案,只是编辑了一下。 我发现这个问题,因为这是我现在的问题。 你能给我任何想法或build议吗? 感谢您的任何帮助或build议,你可以给。

如何设置标签高度自动调整阅读更多/更less使用Swift 3?

我想在最后创build带有Read More / Read Less的段落。 这是我的代码; func getLabelHeight(text: String, width: CGFloat, font: UIFont) -> CGFloat { let lbl = UILabel(frame: .zero) lbl.frame.size.width = width lbl.font = font lbl.numberOfLines = 0 lbl.text = text lbl.sizeToFit() lbl.adjustsFontSizeToFitWidth = true return lbl.frame.size.height } @IBAction func btnReadMore(_ sender: Any) { if isLabelAtMaxHeight { btnReadmore.setTitle(NSLocalizedString("Read more", comment: ""), for: .normal) […]

如何上传一个mp3文件高达5 MB的大小在web服务器上的iPhone

我想从我的iPhone应用程序上传一个audio文件到networking服务器,但是当我把它转换成NSData的时候,它将花费30到40分钟的转换,所以你可以给它更好的解决scheme。

UIUserNotificationSettings不能正常工作?

我有下面的代码,我用来决定用户是否已授予本地通知的权限: UIUserNotificationSettings *grantedSettings = [[UIApplication sharedApplication] currentUserNotificationSettings]; if (grantedSettings.types == UIUserNotificationTypeNone) { NSLog(@"No permission granted"); //IF AND ONLY IF alerts are wanted by raymio user! FIX UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Notice" message:@"You need to enable notifications to be able to receive sun alerts!" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* OKAction = [UIAlertAction actionWithTitle:@"Go to Settings now" style:UIAlertActionStyleDefault handler:^(UIAlertAction * […]

恢复购买:非消费品

我已经完成了一个小应用程序,我有一个非消耗品购买选项。 它在App Store上。 购买产品运行正常。 这是我的恢复购买function,似乎什么都不做。 我已经为恢复购买@IBAction添加了这个代码: @IBAction func restorePurchases(sender: AnyObject) { SKPaymentQueue.defaultQueue().addTransactionObserver(self) SKPaymentQueue.defaultQueue().restoreCompletedTransactions() } 但是当我点击还原购买button时,什么也没有发生。 我想我必须添加一个函数来检查恢复是否成功。 我打算修改以下代码: @IBAction func restorePurchases(sender: AnyObject) { SKPaymentQueue.defaultQueue().addTransactionObserver(self) SKPaymentQueue.defaultQueue().restoreCompletedTransactions() } func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) { for transaction:AnyObject in transactions { if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{ switch trans.transactionState { case .Restored: SKPaymentQueue.defaultQueue().finishTransaction(transaction as SKPaymentTransaction) var alert = […]

与AVPlayer的平移手势

这个function对我的应用程序非常重要,并且真的很想帮助一下。 基本上,我想添加一个UIPanGestureRecognizer到video播放器,以便用户可以用手势快进/倒带video。 苹果有一些使用Swift 3的示例代码,并且已经创build了整个video播放器。 唯一缺less的是UIPanGestureRecognizer 。 这是链接: https : //developer.apple.com/library/content/samplecode/AVFoundationSimplePlayer-iOS/Introduction/Intro.html#//apple_ref/doc/uid/TP40016103 在viewWillAppear我添加了这样的手势: let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture)) view.addGestureRecognizer(panGesture) 这是有点工作的代码。 目前正在擦洗。 问题是,每次我开始平移手势,video跳到中间,我从那里开始。 而不是从当前video的快进/快退,平移手势将video跳到中间,然后允许我快进/快退,这是不好的。 func handlePanGesture(sender: UIPanGestureRecognizer) { switch sender.state { case .began, .changed: let translation = sender.translation(in: self.view) var horizontalTranslation = Float(translation.x) let durationInSeconds = Float(CMTimeGetSeconds(player.currentItem!.asset.duration)) // Using 275 as the limit for delta along […]