2013-10-18 30 views
2

你好,我深化發展爲Windows和Mac是註冊一個URI方案註冊一個單聲道的應用程序的URI方案在OSX

static void RegisterURI() 
    { 
     if (Environment.OSVersion.Platform.ToString() == "Unix") //I'll never use it on any linux machine so it should be OK 
     { 
      //What should I put HERE ?? 
     } 
     else 
     { 
      //on récupère le chemin de l'assembly 
      string MyPos = System.Reflection.Assembly.GetAssembly(typeof(Program)).Location; 

      var protocol = Registry.ClassesRoot 
       .CreateSubKey("serialcodereader"); 
      protocol.SetValue("", "URL:Lancer l'écouteur de liseuse de code barre COM"); 
      protocol.SetValue("URL Protocol", ""); 
      var icon = protocol.CreateSubKey("DefaultIcon"); 
      icon.SetValue("", MyPos + ",1"); 
      var command = protocol.CreateSubKey("shell").CreateSubKey("open").CreateSubKey("command"); 
      command.SetValue("", '"' + MyPos + '"'); 
     } 
    } 

這裏的應用程序是我使用的Windows代碼,但我該怎麼辦它適用於OSX?

PS:好的知道:我從來沒有使用過任何一臺Mac,甚至iPhone在我的生活,所以保持簡單蒙山:-)

回答

0

我類似的東西正在處理這些奇怪的動物。 我不建議浪費一定的時間檢查此:()NSBundle.MainBundle.InfoDictionary.ToString

並檢查此源代碼:因爲它們使用一個NSBundle結構在運行時改變它https://github.com/mono/monodevelop/blob/master/main/src/addins/MacPlatform/MacPlatform.cs

只要我找到了一些解決方案,我會與你分享。


我已經到了功能解決方案。

  1. 我拿起從這個博客的一些信息:https://mhut.ch/journal/2010/01/24/creating_mac_app_bundle_for_gtk_app並修改了劇本有
  2. 我寫了爲了使用單是在Windows/Linux環境
  3. 可重複使用在該應用程序,我一個C#/ GTK應用程序使用了您使用的一些方法來關聯Windows環境中的URL模式。
  4. 我寫了一個.ini文件描述了我的申請
  5. 我寫了一個bash腳本,需要編譯的應用程序,.ini文件,圖標並創建一個蘋果包文件
  6. 我用單個URL從HTML調用測試頁

myProject.ini

[project] 
CFBundleExecutable=ExecutableName 
CFBundleName="Human Readable Executable Name" 
CFBundleVersion="1.0" 
REV_DOMAIN="com.sample" 
URLScheme="myapp" 
# src is where Mono left your executable 
src='/Users/myself/Projects/MyApp/MyApp/bin/Release/' 
CFBundleURLIconFile='appicons.icns' 

用法樣品:

$ build-mac-app.sh myProject 

這將產生一個帶'.app'擴展名的文件夾,你需要運行它。 首先,請記住運行它以便MacOS進行關聯;其次,請注意該方案的用法,因爲如果您在其他開發中使用了url方案,它將失敗或打開其他應用程序。

的HTML測試文件

< A HREF = 「MYAPP:// coisa-A-SER-assinada」 >集團對testaröassinador < /一個>

的建設者腳本

我最初寫在pt-br中,原來是d今天 eveloped 用於內部使用

#!/bin/bash 

echo "" 
echo "EDortta/build-mac-app.sh" 
echo "Construtor de aplicativos para MacOSx" 
echo "Este script usa a saída gerada por MonoDevelop C#/Gtk" 
echo "e produz um Mac App Bundle pronto para ser distribuido" 
echo "------------------------------------------------------" 
if [ -f "$1" ]; then 
    config="$1" 
    CFBundleExecutable=`cat $config | sed -n '/\[project\]/,/\[.*\]/p' | awk -F= '/CFBundleExecutable/{print $2}' | tr -d '"' | tr -d "'"` 
    CFBundleName=`cat $config | sed -n '/\[project\]/,/\[.*\]/p' | awk -F= '/CFBundleName/{print $2}' | tr -d '"' | tr -d "'"` 
    CFBundleVersion=`cat $config | sed -n '/\[project\]/,/\[.*\]/p' | awk -F= '/CFBundleVersion/{print $2}' | tr -d '"' | tr -d "'"` 
    REV_DOMAIN=`cat $config | sed -n '/\[project\]/,/\[.*\]/p' | awk -F= '/REV_DOMAIN/{print $2}' | tr -d '"' | tr -d "'"` 
    CFBundleURLIconFile=`cat $config | sed -n '/\[project\]/,/\[.*\]/p' | awk -F= '/CFBundleURLIconFile/{print $2}' | tr -d '"' | tr -d "'"` 
    URLScheme=`cat $config | sed -n '/\[project\]/,/\[.*\]/p' | awk -F= '/URLScheme/{print $2}' | tr -d '"' | tr -d "'"` 
    src=`cat $config | sed -n '/\[project\]/,/\[.*\]/p' | awk -F= '/src/{print $2}' | tr -d '"' | tr -d "'"` 

    echo "src=$src" 

    if [ ! -d "$CFBundleExecutable.app" ]; then 
    mkdir "$CFBundleExecutable.app" 
    rsync -rvt mac-skel/* "$CFBundleExecutable.app/" 

    sed -i -e "s/%CFBundleExecutable%/$CFBundleExecutable/g" "$CFBundleExecutable.app/Contents/Info.plist" 
    sed -i -e "s/%CFBundleName%/$CFBundleName/g" "$CFBundleExecutable.app/Contents/Info.plist" 
    sed -i -e "s/%CFBundleVersion%/$CFBundleVersion/g" "$CFBundleExecutable.app/Contents/Info.plist" 
    sed -i -e "s/%REV_DOMAIN%/$REV_DOMAIN/g" "$CFBundleExecutable.app/Contents/Info.plist" 
    sed -i -e "s/%URLScheme%/$URLScheme/g" "$CFBundleExecutable.app/Contents/Info.plist" 
    sed -i -e "s/%CFBundleURLIconFile%/$CFBundleURLIconFile/g" "$CFBundleExecutable.app/Contents/Info.plist" 

    if [ -f "$CFBundleExecutable.app/Contents/Info.plist-e" ]; then 
     rm -f "$CFBundleExecutable.app/Contents/Info.plist-e" 
    fi 

    if [ -f "$CFBundleURLIconFile" ]; then 
     cp "$CFBundleURLIconFile" "$CFBundleExecutable.app/Contents/Resources/$CFBundleExecutable.icns" 
    fi 

    mv "$CFBundleExecutable.app/Contents/MacOS/appname.sh" "$CFBundleExecutable.app/Contents/MacOS/$CFBundleExecutable.sh" 
    cp -r "$src/" "$CFBundleExecutable.app/Contents/MacOS/" 

    sed -i -e "s/%CFBundleExecutable%/$CFBundleExecutable/g" "$CFBundleExecutable.app/Contents/MacOS/$CFBundleExecutable.sh" 
    sed -i -e "s/%CFBundleName%/$CFBundleName/g" "$CFBundleExecutable.app/Contents/MacOS/$CFBundleExecutable.sh" 

    if [ -f "$CFBundleExecutable.app/Contents/MacOS/$CFBundleExecutable.sh-e" ]; then 
     rm -f "$CFBundleExecutable.app/Contents/MacOS/$CFBundleExecutable.sh-e" 
    fi 

    chmod +x "$CFBundleExecutable.app/Contents/MacOS/$CFBundleExecutable.sh" 

    else 
    echo "$CFBundleExecutable.app já existe" 
    echo "Por favor, considere remover a pasta" 
    fi 
else 
    echo "Indique o seu projeto C#/GTK" 
    echo "Caso precise de um exemplo, use project-sample.ini" 
fi 

場景結構

在的「build-mac-app.sh」相同的杆和應用程序圖標的背後(移動或從複製的項目或其他來源)有一個與這些文件中的MAC-skel中的文件夾:

mac-skel/ 
└── Contents 
    ├── Info.plist 
    ├── MacOS 
    │   └── appname.sh 
    └── Resources 

MAC-的skel /Contents/Info.plist

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>CFBundleDevelopmentRegion</key> 
    <string>pt-br</string> 
    <key>CFBundleExecutable</key> 
    <string>MacOS/%CFBundleExecutable%.sh</string> 
    <key>CFBundleIconFile</key> 
    <string>../Resources/%CFBundleExecutable%.icns</string> 
    <key>CFBundleIdentifier</key> 
    <string>%REV_DOMAIN%.%CFBundleExecutable%</string> 
    <key>CFBundleInfoDictionaryVersion</key> 
    <string>6.0</string> 
    <key>CFBundleName</key> 
    <string>%CFBundleName%</string> 
    <key>CFBundlePackageType</key> 
    <string>APPL</string> 
    <key>CFBundleShortVersionString</key> 
    <string>%CFBundleVersion%</string> 
    <key>CFBundleSignature</key> 
    <string>xmmd</string> 
    <key>CFBundleVersion</key> 
    <string>%CFBundleVersion%</string> 
    <key>NSAppleScriptEnabled</key> 
    <string>NO</string> 
    <key>CFBundleURLTypes</key> 
    <array> 
     <dict> 
      <key>CFBundleURLIconFile</key> 
      <string>%CFBundleURLIconFile%</string> 
      <key>CFBundleURLName</key> 
      <string>%REV_DOMAIN%.%CFBundleExecutable%</string> 
      <key>CFBundleURLSchemes</key> 
      <array> 
       <string>%URLScheme%</string> 
      </array> 
      <key>CFBundleURLTypes</key> 
      <string>Editor</string> 
     </dict> 
    </array> 
</dict> 
</plist> 

MAC-的skel /內容/ MacOS的/ appname.sh 這是從博客的人把顯示

#!/bin/sh 

#get the bundle's MacOS directory full path 
DIR=$(cd "$(dirname "$0")"; pwd) 

#change these values to match your app 
EXE_PATH="$DIR\%CFBundleExecutable%.exe" 
PROCESS_NAME="%CFBundleExecutable%" 
BUNDLENAME="%CFBundleName%" 

#set up environment 
MONO_FRAMEWORK_PATH=/Library/Frameworks/Mono.framework/Versions/Current 
export DYLD_FALLBACK_LIBRARY_PATH="$DIR:$MONO_FRAMEWORK_PATH/lib:/lib:/usr/lib" 
export PATH="$MONO_FRAMEWORK_PATH/bin:$PATH" 

#mono version check 
REQUIRED_MAJOR=2 
REQUIRED_MINOR=4 

VERSION_TITLE="$BUNDLENAME Não pode ser aberta" 
VERSION_MSG="$BUNDLENAME requer o Framework Mono versão $REQUIRED_MAJOR.$REQUIRED_MINOR ou posterior." 
DOWNLOAD_URL="http://www.go-mono.com/mono-downloads/download.html" 

MONO_VERSION="$(mono --version | grep 'Mono JIT compiler version ' | cut -f5 -d\)" 
MONO_VERSION_MAJOR="$(echo $MONO_VERSION | cut -f1 -d.)" 
MONO_VERSION_MINOR="$(echo $MONO_VERSION | cut -f2 -d.)" 
if [ -z "$MONO_VERSION" ] \ 
    || [ $MONO_VERSION_MAJOR -lt $REQUIRED_MAJOR ] \ 
    || [ $MONO_VERSION_MAJOR -eq $REQUIRED_MAJOR -a $MONO_VERSION_MINOR -lt $REQUIRED_MINOR ] 
then 
    osascript \ 
    -e "set question to display dialog \"$VERSION_MSG\" with title \"$VERSION_TITLE\" buttons {\"Cancelar\", \"Baixar...\"} default button 2" \ 
    -e "if button returned of question is equal to \"Baixar...\" then open location \"$DOWNLOAD_URL\"" 
    echo "$VERSION_TITLE" 
    echo "$VERSION_MSG" 
    exit 1 
fi 

#get an exec command that will work on the current OS version 
OSX_VERSION=$(uname -r | cut -f1 -d.) 
if [ $OSX_VERSION -lt 9 ]; then # If OSX version is 10.4 
    MONO_EXEC="exec mono" 
else 
    MONO_EXEC="exec -a \"$PROCESS_NAME\" mono" 
fi 

#create log file directory if it doesn't exist 
LOG_FILE="$HOME/Library/Logs/$BUNDLENAME/$BUNDLENAME.log" 
mkdir -p "`dirname \"$LOG_FILE\"`" 

#run app using mono 
$MONO_EXEC $MONO_OPTIONS "$EXE_PATH" $* 2>&1 1> "$LOG_FILE" 
相關問題