Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

ios - Is there a similar function to "applicationWillTerminate()", i can use on AppleWatch?

I need to save data in NSUserDefaults before the AppleWatch App will crash. Otherwise the iOS App will think the AppleWatch App is still running and thats not working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your underlying goal, I think, is that you want to ensure that the Containing App is aware when its Apple WatchKit App Extension has crashed.

You can achieve this by getting the Watchkit Extension to periodically send out a Darwin Notification which the containing app subscribes to. Then when the containing app does not get a message from the extension within some timeout limit, it knows the WatchKit extension crashed. This is the most lightweight way I know to achieve this.

Another way is to make the WatchKit app extension periodically call:

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

It is not as lightweight, but has the advantage of allowing you to supply some dictionary data, such as a timestamp value or sequence number.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...