2015-01-11 4 views
7

मैं अपने ऐप्पल वॉच ऐप के मूल एप्लिकेशन को खोलने की कोशिश कर रहा हूं।मैं अपने वॉचकिट ऐप से आईफोन पर मूल ऐप कैसे खोल सकता हूं?

Xcode बीटा 2 में हम इस कोड का उपयोग कर सकते हैं:

WKInterFaceController.openParentApplication 

हालांकि, Xcode बीटा 3 में मैं नहीं है कि कोड किसी भी अब नहीं मिल सकीं। अब मुझे नहीं पता कि वॉच ऐप से पैरेंट एप्लिकेशन कैसे खोलें। कृपया मदद करे।

उत्तर

15

The Objective-C method है:

+ (BOOL)openParentApplication:(NSDictionary *)userInfo 
        reply:(void (^)(NSDictionary *replyInfo, 
            NSError *error))reply 

The Swift method है:

class func openParentApplication(_ userInfo: [NSObject : AnyObject]!, 
        reply reply: (([NSObject : AnyObject]!, 
            NSError!) -> Void)!) -> Bool 

तो आप अपने WatchKit विस्तार से इसे सक्रिय करने के लिए में एक उत्तर() ब्लॉक iPhone आवेदन पारित करने के लिए की जरूरत है। यहाँ उदाहरण के लिए एक ही रास्ता यह लागू किया जा सकता है,:

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply { 
NSString * request = [userInfo objectForKey:@"requestString"]; 

if ([request isEqualToString:@"executeMethodA"]) { 
    // Do whatever you want to do when sent the message. For instance... 
    [self executeMethodABC]; 
} 

// This is just an example of what you could return. The one requirement is 
// you do have to execute the reply block, even if it is just to 'reply(nil)'. 
// All of the objects in the dictionary [must be serializable to a property list file][3]. 
// If necessary, you can covert other objects to NSData blobs first. 
NSArray * objects = [[NSArray alloc] initWithObjects:myObjectA, myObjectB, myObjectC, nil]; 
NSArray * keys = [[NSArray alloc] initWithObjects:@"objectAName", @"objectBName", @"objectCName", nil]; 
NSDictionary * replyContent = [[NSDictionary alloc] initWithObjects:objects forKeys:keys]; 

reply(replyContent); 
} 

WKInterfaceController विधि openParentApplication: जबाब:

NSString *requestString = [NSString stringWithFormat:@"executeMethodA"]; // This string is arbitrary, just must match here and at the iPhone side of the implementation. 
NSDictionary *applicationData = [[NSDictionary alloc] initWithObjects:@[requestString] forKeys:@[@"theRequestString"]]; 

[WKInterfaceController openParentApplication:applicationData reply:^(NSDictionary *replyInfo, NSError *error) { 
    NSLog(@"\nReply info: %@\nError: %@",replyInfo, error); 
    }]; 

आपका iPhone आवेदन के AppDelegate निम्न विधि को लागू करने की जरूरत है पृष्ठभूमि में युक्त ऐप्लिकेशन को लॉन्च जब आईफोन (या आईओएस सिम्युलेटर) अनलॉक या लॉक होता है। ध्यान दें कि ऐप्पल के बयान से संकेत मिलता है कि वॉचकिट एक्सटेंशन हमेशा आपके आईफोन एप्लिकेशन को पृष्ठभूमि में लॉन्च करने का इरादा रखता था, और यह सिम्युलेटर का केवल एक कार्यान्वयन विवरण था जो पिछले बीटा में अग्रभूमि में आपके आईफोन एप्लिकेशन को लॉन्च करने के लिए दिखाई देता था।

यदि आप अपने वॉचकिट ऐप और एक ही समय में चल रहे अपने आईफोन ऐप का परीक्षण करना चाहते हैं, तो बस स्कीम मेनू के तहत एक्सकोड से वॉचकिट ऐप लॉन्च करें और फिर अपने स्प्रिंगबोर्ड आइकन पर क्लिक करके सिम्युलेटर में मैन्युअल रूप से अपना आईफोन ऐप लॉन्च करें ।

+0

मैं Xcode 6 beta3 में इस समारोह में नहीं देखा था। क्या आपने इसे देखा? –

+2

हेउ ने कहा, "क्या आपने इसे जांच लिया है" आपके प्रश्न का उत्तर देने वाले व्यक्ति को, इसे स्वयं जांचने के बिना, महान स्टैक ओवरफ्लो अभ्यास नहीं है। क्योंकि यह स्पष्ट है कि आपने इसे जांच नहीं लिया: https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/index।एचटीएमएल # // apple_ref/occ/clm/WKInterfaceController/openParent आवेदन: उत्तर: –

+1

@DuncanBabbage यह उत्तर गलत है। 'openParentAplication 'फोन पर केवल अग्रभूमि में फोन लॉन्च नहीं करेगा। आप मूल प्रश्न का उत्तर नहीं देते हैं। –

5

यदि आपको अपने मूल ऐप को अग्रभूमि में खोलने की आवश्यकता है, तो Handoff का उपयोग करें!

उदाहरण:

कहीं दोनों के लिए साझा:

updateUserActivity(sharedUserActivityType, userInfo: [sharedIdentifierKey : 123456], webpageURL: nil) 
अनुप्रयोग प्रतिनिधि में अपने iPhone पर

:

static let sharedUserActivityType = "com.yourcompany.yourapp.youraction" 
static let sharedIdentifierKey = "identifier" 
अपनी घड़ी पर

func application(application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool { 
    if (userActivityType == sharedUserActivityType) { 
     return true 
    } 
    return false 
} 

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]!) -> Void) -> Bool { 
    if (userActivity.activityType == sharedUserActivityType) { 
     if let userInfo = userActivity.userInfo as? [String : AnyObject] { 
      if let identifier = userInfo[sharedIdentifierKey] as? Int { 
       //Do something 
       let alert = UIAlertView(title: "Handoff", message: "Handoff has been triggered for identifier \(identifier)" , delegate: nil, cancelButtonTitle: "Thanks for the info!") 
       alert.show() 
       return true 
      } 
     } 
    } 
    return false 
} 

और अंत में (यह चरण महत्वपूर्ण है !!!): अपने Info.plist (रों)

enter image description here

+0

क्या आप हैंडऑफ का उपयोग करके अग्रभूमि में पैरेंट ऐप खोलने के लिए डेमो प्रोजेक्ट प्रदान कर सकते हैं! –

संबंधित मुद्दे