【问题标题】:IOS 9 beta 5 : CGPDFDocumentCreateWithURL is return nil only password protected pdf fileIOS 9 beta 5:CGPDFDocumentCreateWithURL 仅返回 nil 受密码保护的 pdf 文件
【发布时间】:2015-08-11 06:05:14
【问题描述】:

我正在使用以下行来创建 PDF 参考:

**********CGPDFDocumentRef thePDFDocRef = CGPDFDocumentCreateWithURL(theURL);**********

thePDFDocRef 返回 NULL,但在没有密码保护的文件的情况下加载也可以正常工作 ios 9 beta 5。

只有 ios 9 beta 5 有问题,但它适用于 ios 9 beta 4 及以下版本,如 ios 8、7、6 等...

 CGPDFDocumentRef CGPDFDocumentCreateX(CFURLRef theURL, NSString *password)
{
CGPDFDocumentRef thePDFDocRef = NULL;

if (theURL != NULL) // Check for non-NULL CFURLRef
{
    thePDFDocRef = CGPDFDocumentCreateWithURL(theURL);

    if (thePDFDocRef != NULL) // Check for non-NULL CGPDFDocRef
    {
        if (CGPDFDocumentIsEncrypted(thePDFDocRef) == TRUE) // Encrypted
        {
            // Try a blank password first, per Apple's Quartz PDF example

            if (CGPDFDocumentUnlockWithPassword(thePDFDocRef, "") == FALSE)
            {
                // Nope, now let's try the provided password to unlock the PDF

                if ((password != nil) && ([password length] > 0)) // Not blank?
                {
                    char text[128]; // char array buffer for the string conversion

                    [password getCString:text maxLength:126 encoding:NSUTF8StringEncoding];

                    if (CGPDFDocumentUnlockWithPassword(thePDFDocRef, text) == FALSE) // Log failure
                    {
                        #ifdef DEBUG
                            NSLog(@"CGPDFDocumentCreateX: Unable to unlock [%@] with", theURL);
                        #endif
                    }
                }
            }

            if (CGPDFDocumentIsUnlocked(thePDFDocRef) == FALSE) // Cleanup unlock failure
            {
                CGPDFDocumentRelease(thePDFDocRef), thePDFDocRef = NULL;
            }
        }
    }
}
else // Log an error diagnostic
{
    #ifdef DEBUG
        NSLog(@"CGPDFDocumentCreateX: theURL == NULL");
    #endif
}

return thePDFDocRef;

}

【问题讨论】:

  • 人们已经在Radar 上发出了关于这个问题的声音,所以祈祷会很快被Apple 修复;这是一个 iOS9b5 错误。
  • 如何在那里添加噪音?

标签: iphone xcode pdf ios9


【解决方案1】:

我在 iOS 9 Beta 5 中也发现了同样的问题。 预览不要求输入密码或打开受保护的 PDF。

iOS 邮件应用程序中的行为也相同。 STEP : 将pdf附加到邮件并尝试打开...

必须是 iOS 9 Beta 5 的错误...

【讨论】:

  • Xcode 7 GM 仍然有同样的问题。有什么解决办法吗?
  • 你找到任何解决方案了吗?因为我在加载“https”url时遇到了同样的问题,所以在加载“http”url时它工作得很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-23
  • 1970-01-01
  • 2021-03-28
  • 2011-02-02
  • 2012-09-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多