我的应用扩展程序需要从许多网站打开URL.我做如下:
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url, NSError *error) {
NSLog(@"URL: %@",url);
Run Code Online (Sandbox Code Playgroud)
我可以获取URL,但此时我收到此错误:
App Transport Security已阻止明文HTTP(http://)资源加载,因为它不安全.可以通过应用程序的Info.plist文件配置临时例外.
我试图完全关闭ATS,
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key> <true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我无法在NSExceptionDomain中列出网站.我试过模拟器和设备.有人可以帮忙吗?
编辑
我认为导致问题的代码是这样的:
NSString* htmlString = [NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding]
Run Code Online (Sandbox Code Playgroud)
我在url log之后使用这行代码将html作为纯文本.
在我的iOS应用程序中创建一个pdf programmaicallly我在mobile.tut +上关注本教程:
http://mobile.tutsplus.com/tutorials/iphone/generating-pdf-documents/
但是iOS7中现在已经弃用了两种方法,但是xcode建议使用而不是旧方法似乎不起作用.有人有想法吗?
谢谢!
- (CGRect)addText:(NSString*)text withFrame:(CGRect)frame fontSize:(float)fontSize{
UIFont *font = [UIFont fontWithName:@"HelveticaNeue-Light" size:fontSize];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSTextAlignmentNatural;
NSDictionary*attributi = @{ NSForegroundColorAttributeName: [UIColor blackColor],NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraph};
NSStringDrawingContext* drawCont = [[NSStringDrawingContext alloc]init];
drawCont.minimumScaleFactor = 0.0;
//IOS6 deprecated method
// CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(_pageSize.width - 2*20-2*20, _pageSize.height - 2*20 - 2*20) lineBreakMode:NSLineBreakByWordWrapping];
//IOS7 method suggested by xcode
CGRect stringSIZ = [text boundingRectWithSize:CGSizeMake(_pageSize.width - 2*20-2*20, _pageSize.height - 2*20 - 2*20) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributi context:drawCont]; …
Run Code Online (Sandbox Code Playgroud) 我需要在我的应用程序的第一次运行时从主包中复制一些png到文档文件夹.我需要它,因为我必须将这些图像的文件路径保存在核心数据实体中.
我试过这种方式,但它不起作用,有谁知道为什么?
// to copy image from main bundle to documents folder
NSString* mainBundleFilePath = [[NSBundle mainBundle] pathForResource:@"SbriciolataDiRicotta" ofType:@"png"];
NSArray *destPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [destPath objectAtIndex:0];
NSData *mainBundleFile = [NSData dataWithContentsOfFile:mainBundleFilePath];
[[NSFileManager defaultManager] createFileAtPath:documentsDirectory
contents:mainBundleFile
attributes:nil];
// to save the file path
NSString*nomeImmagine = [[NSString alloc] initWithFormat:@"SbriciolataDiRicotta"];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/%@.png",documentsDirectory, nomeImmagine];
Run Code Online (Sandbox Code Playgroud)
谢谢