iOS 9 Error:
- Method override for the designated initializer of the superclass ‘-init’ not found
Solution: created own init function and parse empty value.
Watch OS2 Errors
- Target specifies product type ‘com.apple.product-type.application.watchapp’, but there’s no such product type for the ‘watchsimulator’ platform
Solution: Re-create the new watch os2 project and move source code
2. Debug on Simulator :
2.1 empty screen.
Solution: Scheme settings
- The Watch Extension Scheme builds 3 Target: iPhone (2 dependencies) + Extension (no dependencies) + Watch App. Running Extension Scheme on iPhone simulator – works!
2.2 the WatchKit breakpoints are not working? In Debug Navigator: Watchkitextension installing and waiting to attach.
Solution: Install Xcode 7 beta3 -> OK.
2.3. To be able to turn off the Watch with long press on Power -> no charger !
3. Error Launching ‘WatchKit Extension’:
3.0 Change the Signing Team to my private Apple ID (for all 3: app, ext, watch) -> Free Provisioning.
3.1 Invalid Bundle – No Apple Watch Binary
Solution: Make sure the Extension and the Watchkit App targets are built first, then run the Watchkit App later on the Watch simulator -> OK !
3.2 ld: -weak_library and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together
Solution: just have the bitcode for Watch app only.
4. Deploying Glance: on Simulator okay, debug hit breakpoints. On real Watch:To Do.
5. Deploying App on iPhone:
The flow that works:
- In iPhone’s Watch-remove app from Watch.
- Remove FXDebug from iPhone.
- Run the WatchExtension scheme on the iPhone.
- In iPhone’s Watch -install the app on Watch.
- Run the app on Watch and then FXDebug on phone.
- Solution: move the plist to Watch App, not in Watch Extension! —> Not always running, sometimes crashed after not running for 30 seconds.
- Solution: mock the data, not reading from plist. —> Even when mocking the data, not reading -> it still takes a long time to run!
7. Debug Communication:
Solution: Use Attach-To-Process to Attach the Debugger to the iPhone app.
- First run the WatchExtension (on WatchSimulator)
- Then run the Debug app on iPhone Simulator
- Then Debug- AttachToProcess- AppName (iPhoneSimulator)
It is recommended to use plist for large data, NSUserDefaults for user settings. So any < 10 strings can be saved to NSUserDefaults, larger files go to plist !
If data is not already in NSUserDefaults, use registerDefaults:
let prefs = NSBundle.mainBundle().pathForResource("UserDefaults", ofType: "plist"); let dict = NSDictionary(contentsOfFile: prefs!); let defaults:NSDictionary! = dict?.valueForKey("defaults") as! NSDictionary; NSUserDefaults.standardUserDefaults().registerDefaults(defaults); NSUserDefaults.standardUserDefaults().synchronize();
Change Notification - observeValueForKeyPath:ofObject:change:context:Registering for observation
- addObserver:forKeyPath:options:context: Notify observers of changes:
- willChangeValueForKey:(New in watchOS 2.0)
- didChangeValueForKey:(New in watchOS 2.0)
- willChange:valuesAtIndexes:forKey:(New in watchOS 2.0)
- didChange:valuesAtIndexes:forKey:(New in watchOS 2.0)
- willChangeValueForKey:withSetMutation:usingObjects: - didChangeValueForKey:withSetMutation:usingObjects:
How to use KVO in Watch-OS-2 for Table:
1. The observeValueForKeyPath: should be implemented on the Observer, not the One whose properties are being observed.
2. The willActivate and then didDeactivate are being called on the second Page when the app launches, not only the first page.
3. For second page, the observeValueForKeyPath(2) is also called on launch. The order is (1)awakeWithContext, (2)observeValueForKeyPath, (3)willActivate, (4)didDeactivate. But the didAppear is not called for the second page (it’s not visible). On swiping to it, the willActivate and didAppear of page 2 are called.