Objective-C编程从另一个应用程序调用应用程序

时间:2009-11-13 09:44:13

标签: iphone objective-c

我需要开发一个需要调用本地主机中的另一个应用程序的应用程序。我已经在stackoverflow中发布了相同的问题,我得到了anwer并根据它实现了它。但我没有在iPhone模拟器中获得输出。在编码中指导我在调试时出现的错误是什么

  

块引用

调试器出错:无法模拟应用程序:iPhone模拟器无法安装应用程序。

#import "ModuleManagerAppDelegate.h"   
@implementation ModuleManagerAppDelegate 
@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
 NSURL *myURL = [NSURL URLWithString:@"backgroundcolor:backgroundcolor"];
 [[UIApplication sharedApplication] openURL:myURL]; 
 [window makeKeyAndVisible];  
 [myURL release];
}
- (void)dealloc
{    
 [window release];
    [super dealloc];
}

@end

这是调用应用程序,我将BackgroundColor称为被调用的应用程序。我还在info.plist中注册了BackgroundColor。这是我的info.plist

<?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>English</string>
     <key>CFBundleDisplayName</key>
     <string>${PRODUCT_NAME}</string>
     <key>CFBundleIconFile</key>
     <string></string>
     <key>CFBundleIdentifier</key>
     <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
     <key>CFBundleInfoDictionaryVersion</key>
     <string>6.0</string>
     <key>CFBundleName</key>
     <string>${PRODUCT_NAME}</string>
     <key>CFBundlePackageType</key>
     <string>APPL</string>
     <key>CFBundleSignature</key>
     <string>????</string>
     <key>CFBundleVersion</key>
     <string>1.0</string>
     <key>LSRequiresIPhoneOS</key>
     <true/>
     <key>NSMainNibFile</key>
     <string>MainWindow</string>
     <key>CFBundleURLTypes</key>
     <array>
      <dict>
       <key>CFBundleURLName</key>
       <string>com.xxx.backgroundcolor.xcodeproj</string>
       <key>CFBundleURLSchemes</key>
       <array>
        <string>backgroundcolor.xcodeproj</string>
       </array>
      </dict>
     </array>
    </dict>
    </plist>

这是我所谓的应用程序(BackgroundColor.m)

#import "BackgroundColorAppDelegate.h"

@implementation BackgroundColorAppDelegate

@synthesize window;
@synthesize Orange,Green,Yellow,Blue,Red;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    [window makeKeyAndVisible];

}
-(BOOL)application:(UIApplication *) application handleOpenURL:(NSURL *)url
{
if([[url scheme] isEqualToString:@"backgroundcolor"])
 {
-(IBAction)doOrange
{
 window.backgroundColor=[UIColor orangeColor];
}
-(IBAction)doBlue
{
 window.backgroundColor=[UIColor blueColor];
}
-(IBAction)doGreen
{
 window.backgroundColor=[UIColor greenColor];
}
-(IBAction)doRed
{
 window.backgroundColor=[UIColor redColor];
}
-(IBAction)doYellow
{
 window.backgroundColor=[UIColor yellowColor];
}

}

- (void)dealloc {
    [window release];
    [super dealloc];
}


@end

2 个答案:

答案 0 :(得分:1)

BackgroundColor应用程序的代码有问题。您已经在另一个方法实现(-application:handleOpenURL :)中包含了一系列方法实现(-doOrange,-doBlue等)。编译器应该给你错误。您需要将这些方法实现移出其他方法,并使用switch语句来调用方法。现在,这段代码是荒谬的。

答案 1 :(得分:0)

首先要尝试的是摆脱URL方案中的要点。使用backgroundcolor代替backgroundcolor.xcodeproj