我尝试NSURLSession在iOS 8中使用共享扩展程序上传图像,但在调用后立即出现此错误
[task resume]
Error Domain=NSURLErrorDomain Code=-995 "The operation couldn’t be completed. (NSURLErrorDomain error -995.)"
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:DEFAULT_SHARE_SESSION_ID];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:self.queue];
NSURLRequest *request = [self getMultipartUploadRequest:data url:url albumId:albumId];
// ... saving file here to Documents folder
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request fromFile:url1];
[uploadTask resume];
Run Code Online (Sandbox Code Playgroud)
而且我在控制台中也有这条消息:
Attempted to create a task in a session that has been invalidated
Run Code Online (Sandbox Code Playgroud)
此代码绝对适用于应用程序,但在共享扩展程序中不起作用.我找不到代码-995的含义.
有任何想法吗?
我有一个UILabel包含在UIView固定大小的内容.在UILabel具有动态文本.我怎样才能确保UILabel永远不会比包含UIView更大?
在使用之前AutoLayout,通过简单地使用AdjustsFontSizeToFitWidth它就可以很容易地实现,但我无法再使用Autolayout了.
我应该从增加什么约束上UILabel的UIView?现在它只是领先对齐.
为了同时进行可用的播放和录制,我们使用这些方法来设置AVAudioSession类别:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];
Run Code Online (Sandbox Code Playgroud)
通过这样做,输出音频端口从线路输出扬声器切换到内置扬声器.在循环录制窗口中,我们需要同时从线路输出扬声器和麦克风录音进行播放.要在设置AVAudioSession类别后从线路输出扬声器播放声音,我们使用一种设置输出音频端口的方法:
[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
我们尝试使用AVAudio Engine安排录制和播放.AVAudioEngine连接结构:
// input->inputMixer->mainEqualizer ->tap
// 0 0 |0
// |
// |
// |0 0 0
// recordPlayerNode?recordMixer?meteringMixer?|
// 0 1 0 0 |
// |->mainMixer->out
// |
// volumePlayer?|
// 0 1
Run Code Online (Sandbox Code Playgroud)
执行overrideOutputAudioPort后,录制功能将停止在iPhone 6S及更高版本上运行.我们以这种方式进行录制:
if(self.isHeadsetPluggedIn)
{
volumePlayer.volume = 1;
}
else
{
volumePlayer.volume = 0.000001;
}
[volumePlayer play];
[mainEqualizer installTapOnBus:0 bufferSize:0 format:tempAudioFile.processingFormat block:^(AVAudioPCMBuffer *buf, AVAudioTime *when)
{ …Run Code Online (Sandbox Code Playgroud) 我有一个UITextViews用于显示文本的应用程序(可能是多行),并且在iOS8中正常工作.我通过声明关闭了滚动self.scrollEnabled = false.UITextView在需要的时候会把话语分解成新的行,所有这些似乎都在起作用!
但是,当我在iOS9上运行代码时,UITextView只会显示1行文本(无论有多少行文本).
我意识到当我删除self.scrollEnabled = false线条时,UITextView渲染正确(显示所有线条),但它显然是可以滚动的,这不是意图.
我该怎么做才能UITextView渲染多行并关闭滚动?有没有人见过这个问题或有任何建议?
谢谢!
我想在Apple Pay上设置传递变量,我将其设置NSDictionary为JSON数据,如:
PKPaymentRequest *request = [[PKPaymentRequest alloc] init];
[request setApplicationData:[NSJSONSerialization dataWithJSONObject:@{@"name":@"USER_NAME"} options:NSJSONWritingPrettyPrinted error:nil]];
Run Code Online (Sandbox Code Playgroud)
现在里面:
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion;
Run Code Online (Sandbox Code Playgroud)
我能够访问applicationData作为
NSError* jsonError;
NSDictionary* dataDict = [NSJSONSerialization JSONObjectWithData:payment.token.paymentData options:kNilOptions error:&jsonError];
Run Code Online (Sandbox Code Playgroud)
dataDict [@"header"] [@"applicationData"]包含应用程序数据
但数据是编码的,我想@{@"name":@"USER_NAME"}从applicationData 获得.
我使用 SQLCipher 在我的应用程序中加密 sqlite 数据库。一切正常,但我的应用程序在获取数据库期间运行缓慢。我将PRAGMA kdf_iter更改为 4000,但它仍然很慢。加密之前我没有任何问题。
-(NSError *) openDatabase {
NSError *error = nil;
NSString *databasePath = [self getDatabasePath];
const char *dbpath = [databasePath UTF8String];
int result = sqlite3_open_v2 (dbpath, &db , SQLITE_OPEN_READWRITE , NULL);
if (result == SQLITE_OK) {
sqlite3_exec(db, [@"PRAGMA kdf_iter = '4000';" UTF8String], NULL, NULL, NULL);
sqlite3_exec(db, [@"PRAGMA key = 'password'" UTF8String], NULL, NULL, NULL);
NSLog(@"Password is correct , Database is Activated");
sqlite3_exec(db, [@"PRAGMA cipher = 'aes-256-cfb';" UTF8String], NULL, NULL, NULL);
}
else { …Run Code Online (Sandbox Code Playgroud) 我想要一个添加UITextView到UIStackView编程,但它不会出现在屏幕上.
当我检入调试视图层次结构时,它位于视图层次结构中,它有一些约束但不会显示在输出视图中.
这是我的代码:
let stackView = UIStackView()
let textView = UITextView()
let button = UIButton()
stackView.axis = .Horizontal
stackView.spacing = 20
stackView.distribution = UIStackViewDistribution.Fill
button.setImage(UIImage(named:"image1"), forState: .Normal)
button.setImage(UIImage(named:"image2"), forState: .Selected)
textView.textAlignment = NSTextAlignment.Left
textView.textColor = UIColor.blackColor()
textView.editable = true
textView.text = ""
stackView.addArrangedSubview(textView)
stackView.addArrangedSubview(button)
Run Code Online (Sandbox Code Playgroud)
按钮添加正常.但我找不到正确显示TextView的方法!尝试添加如下所示的宽度/高度限制,但它不起作用,或工作不当(取决于变体):
let widthConstraint = NSLayoutConstraint(item: textView,
attribute: NSLayoutAttribute.Width,
relatedBy: NSLayoutRelation.Equal,
toItem: stackView,
attribute: NSLayoutAttribute.Width,
multiplier: 1,
constant: 0)
stackView.addConstraint(widthConstraint)
let heightConstraint = NSLayoutConstraint(item: textView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: stackView, attribute: NSLayoutAttribute.Height, …Run Code Online (Sandbox Code Playgroud) 我想知道最好的方法:
我已经将标记添加为UIViews.例:
let tick = UIView(frame: CGRect(x: xPos, y: (slider.frame.size.height - 10) / 2, width: 2, height: 10))
tick.backgroundColor = UIColor.init(white: 0.7, alpha: 1)
tick.layer.shadowColor = UIColor.white.cgColor
tick.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
tick.layer.shadowOpacity = 1.0
tick.layer.shadowRadius = 0.0
tick.tag = i
slider.insertSubview(tick, belowSubview: slider)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,添加了7个滴答.控制这些子视图的颜色.我使用了标签,并且在滑块的值更改中,使用if-else语句,我将颜色更改为minimumTrackTintColor或maximumTrackTintColor(绿色或灰色).例:
if sender.value == 0 {
slider.viewWithTag(1)?.backgroundColor = slider.maximumTrackTintColor
}else if sender.value <= 5{
slider.viewWithTag(1)?.backgroundColor = slider.minimumTrackTintColor
Run Code Online (Sandbox Code Playgroud)
我真的不喜欢这样做...有更好的方法吗?
我们怎样才能获得两个拇指之间的距离UISlider.我的应用程序包含价格范围选择,我没有用一个拇指.在这里,我需要在拇指上方的标签上显示范围,这些标签也在图像内.
也许有人可以提供帮助,我正在尝试移动我的应用以促进Apple TV的新目标.我创建了新的Storyboard,并以与iOS应用程序相同的方式链接了所有内容.当我尝试启动应用程序时,在AppDelegate执行之后(在进入viewDidLoad初始控制器之前),我得到以下异常.
有任何想法吗?
2015-09-19 12:24:44.629 App TV[46733:3797033] *** Terminating app due to uncaught exception 'CALayerInvalid', reason: 'layer <CATransformLayer: 0x7fc1e0d51fc0> is a part of cycle in its layer tree'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e850105 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010f271deb objc_exception_throw + 48
2 CoreFoundation 0x000000010e85003d +[NSException raise:format:] + 205
3 QuartzCore 0x0000000111d2f74a _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 102
4 QuartzCore 0x0000000111d2f795 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 177
5 QuartzCore 0x0000000111d2f795 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 177
6 QuartzCore 0x0000000111d2f795 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + …Run Code Online (Sandbox Code Playgroud) 首先,我已经对此进行了彻底的研究,但未能找到符合我要求的任何内容.
我的问题是这样的:我在Class1中创建了一个字符串属性,然后如下所示进行合成.
@interface Class1 : UIViewController
{
NSString *testvar;
}
@property (nonatomic, retain) NSString *testvar;
@end
@implementation Class1
@synthesize testvar
- (void)viewDidLoad
{
[super viewDidLoad];
self.testvar = @"Test variable";
}
@end
Run Code Online (Sandbox Code Playgroud)
这适用于定义变量/属性的值,因为它在UIAlertView通过viewDidLoad定义的相同方法显示的测试中工作.当另一个类Class2尝试检索和使用该属性时,会出现问题.第二类使用的代码如下:
Class1 *foo = [[Class1 alloc]init];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Title"
message:foo.testvar
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[foo release];
Run Code Online (Sandbox Code Playgroud)
会发生什么是UIAlertView显示,但没有消息.我相信Class1 testvar属性的值在Class2尝试检索它之前被释放,或者我设置错误.我说这是因为我尝试过同样的事情,但是使用的是int而不是NSString.我在Class1中将int的值设置为3 viewDidLoad,当UIAlertView显示时,它显示int的值,但显示为"0",int的默认值,而不是我的设置值.
作为Objective-C的新手并且还没有很好地掌握内存管理,我认为错误与我设置属性值的位置或方式有关.任何见解将不胜感激.提前致谢.
在我的应用程序中,我使用以下方法从图库中获取视频:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
}
Run Code Online (Sandbox Code Playgroud)
但Apple拒绝了应用程序并要求包含从"文件"应用程序中选择视频项的功能.
这是Apple给我的理由:
我们注意到您的应用程序允许用户查看和选择文件,但它不包括允许用户根据App Store审查指南的要求查看或选择"文件"应用程序和用户的iCloud文档中的项目的功能.
ios ×12
swift ×5
objective-c ×4
apple-tv ×1
applepay ×1
autolayout ×1
avfoundation ×1
class ×1
icloud ×1
ios11 ×1
ios9 ×1
iphone ×1
nsurlsession ×1
properties ×1
sqlcipher ×1
sqlite ×1
swift2 ×1
tvos ×1
uialertview ×1
uilabel ×1
uislider ×1
uistackview ×1
uitextview ×1
uiview ×1
xcode ×1