Reputation: 36078
I'm upgrading my watchOS 1 app to watchOS 2 and noticed there's a ExtensionDelegate
class in new watchOS 2 targets. I tried adding this file to my watchOS 1 app (after updating the deployment version), but it's not hitting the break point in applicationDidFinishLaunching
.
Here's what my class looks like:
import WatchKit
class ExtensionDelegate: NSObject, WKExtensionDelegate {
func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
print("applicationDidFinishLaunching for watchOS")
}
func applicationDidBecomeActive() {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillResignActive() {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, etc.
}
}
Is there more to just adding the file, or did I not upgrade properly?
Upvotes: 0
Views: 802
Reputation:
There's a lot more that changes, than just adding that file.
What you should do is target your project, then choose Editor -> Validate Settings.
The number of changes made are too extensive to list individually; I wouldn't recommend trying to manually upgrade your project.
An alternate approach
You could backup your watchOS 1 files, delete the two watchOS 1 targets within your Xcode project, then select Editor -> Add target. Select watchOS, Application, then WatchKit App.
This will configure the necessary targets and settings for watchOS 2.
You could then add your source code back to the project, but you'd still have to transition your code to watchOS 2 to account for changes such as migrating from shared app groups to using Watch Connectivity.
Update:
Simply adding that file is not enough. Apple determines details about the extension via plist preferences and project settings. If your watch app extension isn't called, something likely didn't get changed correctly. Perhaps it's still running as a watchKit 1 app extension on the phone, instead of using the extension in the watch app bundle?
If you want to try to fix it by hand, here are a couple of things you could check:
Make sure the WatchKit extension Info.plist contains
<key>WKExtensionDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).ExtensionDelegate</string>
Make sure the project.pbxproj
Watch App and Watch Extension product types were changed to include a 2.
productType = "com.apple.product-type.application.watchapp2";
productType = "com.apple.product-type.watchkit2-extension";
There's much more that's changed than those few lines. It's possible other changes were missed, so you may want to delete the targets and start with an empty watch project, to be certain that everything is properly set up. Otherwise, it's trial-and-error discovering what else might not have gotten properly changed.
As an aside, since you ran into problems, you should file a bug report and include your watchKit 1 app, so Apple can fix that Xcode issue.
Upvotes: 2