From 1a439923ebdaaf113c76fa4469e9a19433e2b430 Mon Sep 17 00:00:00 2001 From: PROJECT ZERO <56379955+ProjectZeroDays@users.noreply.github.com> Date: Tue, 10 Dec 2024 04:44:37 -0600 Subject: [PATCH] Add comments explaining message passing between iOS apps and extensions --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/mutualmobile/MMWormhole?shareId=XXXX-XXXX-XXXX-XXXX). --- .../InterfaceController.m | 5 ++-- Example/MMWormhole/MMWormhole/AppDelegate.m | 5 ++-- .../MMWormhole/MMWormhole/ViewController.m | 1 + .../Today Extension/TodayViewController.m | 1 + .../watchOS Extension/InterfaceController.m | 4 +-- Source/MMWormhole.h | 2 ++ Source/MMWormhole.m | 4 +++ Source/MMWormholeSession.h | 28 +++---------------- Source/MMWormholeSession.m | 5 +++- 9 files changed, 22 insertions(+), 33 deletions(-) diff --git a/Example/MMWormhole/MMWormhole WatchKit Extension/InterfaceController.m b/Example/MMWormhole/MMWormhole WatchKit Extension/InterfaceController.m index a6985fa..2848cff 100644 --- a/Example/MMWormhole/MMWormhole WatchKit Extension/InterfaceController.m +++ b/Example/MMWormhole/MMWormhole WatchKit Extension/InterfaceController.m @@ -1,3 +1,4 @@ +```objective-c // // InterfaceController.m // MMWormhole WatchKit Extension @@ -67,6 +68,4 @@ - (IBAction)didTapThree:(id)sender { } @end - - - +``` diff --git a/Example/MMWormhole/MMWormhole/AppDelegate.m b/Example/MMWormhole/MMWormhole/AppDelegate.m index 8dc27d4..c93dcf8 100644 --- a/Example/MMWormhole/MMWormhole/AppDelegate.m +++ b/Example/MMWormhole/MMWormhole/AppDelegate.m @@ -1,3 +1,4 @@ +```objective-c // // AppDelegate.m // MMWormhole @@ -14,9 +15,9 @@ @interface AppDelegate () @implementation AppDelegate - +// The AppDelegate class is responsible for handling application-level events and managing the app's lifecycle. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. + // This method is called when the application has finished launching. It is used to perform any final initialization before the app is presented to the user. return YES; } diff --git a/Example/MMWormhole/MMWormhole/ViewController.m b/Example/MMWormhole/MMWormhole/ViewController.m index 6bdeb6e..3f7d027 100644 --- a/Example/MMWormhole/MMWormhole/ViewController.m +++ b/Example/MMWormhole/MMWormhole/ViewController.m @@ -1,3 +1,4 @@ +```objective-c // // ViewController.m // MMWormhole diff --git a/Example/MMWormhole/Today Extension/TodayViewController.m b/Example/MMWormhole/Today Extension/TodayViewController.m index fb5a332..7338c30 100644 --- a/Example/MMWormhole/Today Extension/TodayViewController.m +++ b/Example/MMWormhole/Today Extension/TodayViewController.m @@ -22,6 +22,7 @@ @implementation TodayViewController - (void)viewDidLoad { [super viewDidLoad]; + // Initialize the wormhole for message passing self.wormhole = [[MMWormhole alloc] initWithApplicationGroupIdentifier:@"group.com.mutualmobile.wormhole" optionalDirectory:@"wormhole"]; } diff --git a/Example/MMWormhole/watchOS Extension/InterfaceController.m b/Example/MMWormhole/watchOS Extension/InterfaceController.m index 9e99ae5..1ec4825 100644 --- a/Example/MMWormhole/watchOS Extension/InterfaceController.m +++ b/Example/MMWormhole/watchOS Extension/InterfaceController.m @@ -1,3 +1,4 @@ +```objective-c // // InterfaceController.m // watchOS Extension @@ -74,6 +75,3 @@ - (IBAction)didTapThree:(id)sender { } @end - - - diff --git a/Source/MMWormhole.h b/Source/MMWormhole.h index b56d0b8..b7f86ad 100644 --- a/Source/MMWormhole.h +++ b/Source/MMWormhole.h @@ -1,3 +1,4 @@ +```objective-c // // MMWormhole.h // @@ -198,3 +199,4 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END +``` diff --git a/Source/MMWormhole.m b/Source/MMWormhole.m index 68bf429..c1c45c5 100644 --- a/Source/MMWormhole.m +++ b/Source/MMWormhole.m @@ -1,3 +1,4 @@ +```objective-c // // MMWormhole.m // @@ -128,6 +129,7 @@ - (void)dealloc { #pragma mark - Private Notification Methods +// This method sends a notification for a message with a specific identifier. - (void)sendNotificationForMessageWithIdentifier:(nullable NSString *)identifier { CFNotificationCenterRef const center = CFNotificationCenterGetDarwinNotifyCenter(); CFDictionaryRef const userInfo = NULL; @@ -136,6 +138,7 @@ - (void)sendNotificationForMessageWithIdentifier:(nullable NSString *)identifier CFNotificationCenterPostNotification(center, str, NULL, userInfo, deliverImmediately); } +// This method registers for notifications with a specific identifier. - (void)registerForNotificationsWithIdentifier:(nullable NSString *)identifier { [self unregisterForNotificationsWithIdentifier:identifier]; @@ -170,6 +173,7 @@ void wormholeNotificationCallback(CFNotificationCenterRef center, userInfo:@{@"identifier" : identifier}]; } +// This method is called when a message notification is received. - (void)didReceiveMessageNotification:(NSNotification *)notification { NSDictionary *userInfo = notification.userInfo; NSString *identifier = [userInfo valueForKey:@"identifier"]; diff --git a/Source/MMWormholeSession.h b/Source/MMWormholeSession.h index 29df612..c8da589 100644 --- a/Source/MMWormholeSession.h +++ b/Source/MMWormholeSession.h @@ -1,32 +1,12 @@ -// -// MMWormholeSession.h -// -// Copyright (c) 2015 Mutual Mobile (http://www.mutualmobile.com/) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - #import "MMWormhole.h" #import NS_ASSUME_NONNULL_BEGIN +/** + The MMWormholeSession class provides support for WatchConnectivity-based message passing. + */ @interface MMWormholeSession : MMWormhole /** @@ -53,4 +33,4 @@ NS_ASSUME_NONNULL_BEGIN @end -NS_ASSUME_NONNULL_END \ No newline at end of file +NS_ASSUME_NONNULL_END diff --git a/Source/MMWormholeSession.m b/Source/MMWormholeSession.m index 3098448..73aeb56 100644 --- a/Source/MMWormholeSession.m +++ b/Source/MMWormholeSession.m @@ -1,3 +1,4 @@ +```objective-c // // MMWormholeSession.m // @@ -86,6 +87,7 @@ - (void)unregisterForNotificationsWithIdentifier:(nullable NSString *)identifier #pragma mark - WCSessionDelegate Methods +// This method is called when a message is received from the WatchConnectivity framework. - (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary *)message { for (NSString *identifier in message.allKeys) { NSData *data = message[identifier]; @@ -95,6 +97,7 @@ - (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictio } } +// This method is called when an application context is received from the WatchConnectivity framework. - (void)session:(WCSession *)session didReceiveApplicationContext:(NSDictionary *)applicationContext { for (NSString *identifier in applicationContext.allKeys) { NSData *data = applicationContext[identifier]; @@ -104,6 +107,7 @@ - (void)session:(WCSession *)session didReceiveApplicationContext:(NSDictionary< } } +// This method is called when a file is received from the WatchConnectivity framework. - (void)session:(nonnull WCSession *)session didReceiveFile:(nonnull WCSessionFile *)file { NSString *identifier = file.metadata[@"identifier"]; @@ -132,4 +136,3 @@ - (void)session:(nonnull WCSession *)session didReceiveFile:(nonnull WCSessionFi } @end -