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 निम्न विधि को लागू करने की जरूरत है पृष्ठभूमि में युक्त ऐप्लिकेशन को लॉन्च जब आईफोन (या आईओएस सिम्युलेटर) अनलॉक या लॉक होता है। ध्यान दें कि ऐप्पल के बयान से संकेत मिलता है कि वॉचकिट एक्सटेंशन हमेशा आपके आईफोन एप्लिकेशन को पृष्ठभूमि में लॉन्च करने का इरादा रखता था, और यह सिम्युलेटर का केवल एक कार्यान्वयन विवरण था जो पिछले बीटा में अग्रभूमि में आपके आईफोन एप्लिकेशन को लॉन्च करने के लिए दिखाई देता था।
यदि आप अपने वॉचकिट ऐप और एक ही समय में चल रहे अपने आईफोन ऐप का परीक्षण करना चाहते हैं, तो बस स्कीम मेनू के तहत एक्सकोड से वॉचकिट ऐप लॉन्च करें और फिर अपने स्प्रिंगबोर्ड आइकन पर क्लिक करके सिम्युलेटर में मैन्युअल रूप से अपना आईफोन ऐप लॉन्च करें ।
मैं Xcode 6 beta3 में इस समारोह में नहीं देखा था। क्या आपने इसे देखा? –
हेउ ने कहा, "क्या आपने इसे जांच लिया है" आपके प्रश्न का उत्तर देने वाले व्यक्ति को, इसे स्वयं जांचने के बिना, महान स्टैक ओवरफ्लो अभ्यास नहीं है। क्योंकि यह स्पष्ट है कि आपने इसे जांच नहीं लिया: https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/index।एचटीएमएल # // apple_ref/occ/clm/WKInterfaceController/openParent आवेदन: उत्तर: –
@DuncanBabbage यह उत्तर गलत है। 'openParentAplication 'फोन पर केवल अग्रभूमि में फोन लॉन्च नहीं करेगा। आप मूल प्रश्न का उत्तर नहीं देते हैं। –