Anchors in help-book not working

帅比萌擦擦* 提交于 2021-02-06 09:11:52

问题


I've double checked everything and hoping someone can find a stupid mistake that I'm not seeing.

I'm trying to build a Apple Help section for my application and it correctly goes to the landing page however none of the anchors work. The landing page is called index.html and the other page is called test.html which is located in the pgs directory.

In index.html I have:

<a href="help:anchor=support bookID=com.company.app_name.help">Link to another page</a>

In test.html I have:

<a name="support"></a>

So here's the steps that I followed in order to get to where I am right now:

1) I built the directory as specified by the Apple documentation

AppName.help/
    Contents/
        Info.plist
        Resources/
            shrd/
            English.lproj/
                index.html
                search.helpindex
                pgs/
                    test.html

2) I built the Help Info.plist as specified in the Apple documentation. Included in the Info.plist I set the CFBundleIdentifier to com.company.app_name.help.

3) In my app Info.plist I set the CFBundleHelpBookFolder to AppName.help and set CFBundleHelpBookName to com.company.app_name.help

4) I then copied the directory that I built into Xcode while ensuring that I selected the option Create Folder References for any added folders.

5) Then I used Help Indexer to index the directory AppName.help. Making sure that I select the option to Index anchor information in all files.I then copied the .helpindex file to the English.lproj folder where it's supposed to be.

That's it. There's a couple of things that I noticed about my application if I place the following link in the index.html file it works correctly.

<a href="pgs/test.html">Click this link</a>                 

Also here is my code for the index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>AppName Help</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="robots" content="noindex" />
    <meta name="AppleTitle" content="AppName Help" />
    <meta name="AppleIcon" content="../shrd/icon.png" />
</head>
<body>
    <a href="help:anchor=support bookID=com.company.app_name.help">Link to another page</a>
</body>

Here is the code for the test.html.

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Testing Links</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="robots" content="anchors" />
    </head>
    <body>
        <a name="support"></a>Does linking work?<br/>

    </body>
</html>

Here is the Info.plist for my Help file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en_us</string>
    <key>CFBundleIdentifier</key>
    <string>com.company.app_name.help</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>AppName</string>
    <key>CFBundlePackageType</key>
    <string>BNDL</string>
    <key>CFBundleShortVersionString</key>
    <string>2</string>
    <key>CFBundleSignature</key>
    <string>hbwr</string>
    <key>CFBundleVersion</key>
    <string>2</string>
    <key>CFBundleHelpBookName</key>
    <string>AppName Help</string>
    <key>HPDBookAccessPath</key>
    <string>index.html</string>
    <key>HPDBookIconPath</key>
    <string>shrd/icon.png</string>
    <key>HPDBookIndexPath</key>
    <string>search.helpindex</string>
    <key>HPDBookKBProduct</key>
    <string>app_name1</string>
    <key>HPDBookKBURL</key>
    <string>http://www.company.com</string>
    <key>HPDBookRemoteURL</key>
    <string>http://www.company.com</string>
    <key>HPDBookTitle</key>
    <string>AppName Help</string>
    <key>HPDBookType</key>
    <string>3</string>
</dict>
</plist>

Also I followed this post:http://www.cocoabuilder.com/archive/cocoa/312037-updating-an-app-help.html to clear out the cache every time I make a change in addition to re-indexing the directory.

Thanks all!


回答1:


Sure David, Thanks for the reminder.

From what I recall and my sloppy documentation I run the following command to index the help documentation files:

hiutil -vCaf ./search.helpindex English.lproj

However one thing that I realized is the index utility will complain any time the &nbsp; character is used. Instead substitute the character &#32;

I think that was the bug in my case.




回答2:


If Everything is proper and and still if help does not work use code below. Not sure about the security concerns thou,you might have to research on deleting files from app. Sometimes app on upgrade does not update the help files and display the cached copy of older help file, which do not contain new anchors. Hence code below clears help cache. Also theres another cleaner method where in you increment the build version of help file in Info.plist which is inside the help bundle not the app info plist. Those fields are CFBundleShortVersionString CFBundleVersion

-(void)clearCacheHelp {
NSArray *arguments1 = [NSArray arrayWithObjects:@"helpd",nil];

NSTask * list1 = [[NSTask alloc] init];
[list1 setLaunchPath:@"/usr/bin/killall"];
[list1 setArguments:arguments1];


NSPipe * out1 = [NSPipe pipe];
[list1 setStandardOutput:out1];

[list1 launch];
[list1 waitUntilExit];


NSString *home = [self homeDirectory];

home = [home stringByAppendingPathComponent:@"Library/Caches/com.apple.helpd"];

NSArray *arguments  = [NSArray arrayWithObjects:@"-rf",home,nil];


NSTask * list = [[NSTask alloc] init];
[list setLaunchPath:@"/bin/rm"];
[list setArguments:arguments];


NSPipe * out = [NSPipe pipe];
[list setStandardOutput:out];

[list launch];
[list waitUntilExit];



NSString *home2 = [self homeDirectory];

home2 = [home2 stringByAppendingPathComponent:@"Library/Caches/com.apple.helpviewer"];

NSArray *arguments2  = [NSArray arrayWithObjects:@"-rf",home2,nil];


NSTask * list2 = [[NSTask alloc] init];
[list2 setLaunchPath:@"/bin/rm"];
[list2 setArguments:arguments2];


NSPipe * out2 = [NSPipe pipe];
[list2 setStandardOutput:out2];

[list2 launch];
[list2 waitUntilExit];


NSArray *arguments3  = [NSArray arrayWithObjects:@"-rf",@"~/Library/Caches/com.apple.helpd",nil];


NSTask * list3 = [[NSTask alloc] init];
[list3 setLaunchPath:@"/bin/rm"];
[list3 setArguments:arguments3];


NSPipe * out3 = [NSPipe pipe];
[list3 setStandardOutput:out3];

[list3 launch];
[list3 waitUntilExit];


NSArray *arguments4  = [NSArray arrayWithObjects:@"-rf",@"~/Library/Caches/com.apple.helpviewer",nil];


NSTask * list4 = [[NSTask alloc] init];
[list4 setLaunchPath:@"/bin/rm"];
[list4 setArguments:arguments4];


NSPipe * out4 = [NSPipe pipe];
[list4 setStandardOutput:out4];

[list4 launch];
[list4 waitUntilExit];


}


来源:https://stackoverflow.com/questions/14913937/anchors-in-help-book-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!