Communicating between the iOS app and the Watch Extension

There are four scenarios where an app and an extension might wish to communicate:

  1. Watch extension to suspended/terminated iOS app - use +[WKInterfaceDevice openParentApplication:reply:] if you need to "wake up" your iOS app. If you simply need to leave data in a place for your iOS app to find it later, then you should write it into the shared group container and have your iOS app consult it when it next needs the information.
  2. Watch extension to running iOS app - use either +[WKInterfaceDevice openParentApplication:reply:] or the Darwin notification center.
  3. iOS app to suspended/terminated Watch extension - Since the Watch extension is only launched in reaction to your Watch app being launched on the Apple Watch, an iOS app cannot launch its corresponding Watch extension. Instead, the app should write whatever data it wants to send to the Watch extension into the shared group container, and the extension should consult it when it next needs the information.
  4. iOS app to to running Watch extension - If your iOS app received the -[<UIApplicationDelegate> application:handleWatchKitExtensionRequest:reply:] message, it should use the system-provided reply block to convey information back to the extension. Otherwise you may use the Darwin notification center to pass information back to the extension.

More information on the Darwin notification center can be found in the Documentation.

watchos2 录音功能实现

  1. [self presentAudioRecordingControllerWithOutputURL:fileUrl
  2. preset:WKAudioRecordingPresetWideBandSpeech
  3. maximumDuration:5.0
  4. actionTitle:@"Some Title"
  5. completion:^(BOOL didSave, NSError * __nullable error) {
  6. NSLog(@"didSave:%d, error:%@", didSave, error);
  7. }];

The extension is not automatically notified of changes to the shared user defaults made by the iOS app, and vice versa. If you would like to be notified, you can do so manually by using the Darwin notification center.

auto engine = LuaEngine::getInstance();

ScriptEngineManager::getInstance()->setScriptEngine(engine);

lua_State* L = engine->getLuaStack()->getLuaState();

int isOpen = luaL_dofile(L, "/Users/game-netease/svn/gzhuabo/Menghuan/src/operation.lua");

if(isOpen != 0)

{

const char* iResult = lua_tostring(L, -1);

NSLog(@"Open Lua Error: %i, %s", isOpen, iResult);

handler(@{@"glanceInfo": @"ERROR"});

}

else

{

lua_getglobal(L, "getGlance");

/*

lua_call

第一个参数:函数的参数个数

第二个参数:函数返回值个数

*/

lua_call(L, 0, 1);

const char* iResult = lua_tostring(L, -1);

NSString *str = [NSString stringWithUTF8String:iResult];

NSLog(@"%@", str);

handler(@{@"glanceInfo": str});

}

NSArray *array = (NSArray *)context;

for (id object in array) {

Activity *obj = (Activity *)[NSKeyedUnarchiver unarchiveObjectWithData: object];

NSLog(@"name: %@, type: %@", obj.m_name, obj.m_type);

NSLog(@"time: %@", obj.m_time);

NSLog(@"donetime: %@", obj.m_doneTime);

}

  1. //活动
  2. @interface Activity : NSObject
  3. @property(nonatomic, retain) NSString *m_name; //名称
  4. @property(nonatomic, retain) NSString *m_type; //日常活动、限时活动、节日活动
  5. @property(nonatomic, retain) NSNumber *m_doneTime; //已经完成次数
  6. @property(nonatomic, retain) NSNumber *m_time; //每日次数
  7. @property(nonatomic, retain) NSNumber *m_doneActiveness; //已经完成活跃度
  8. @property(nonatomic, retain) NSNumber *m_activeness; //每日活跃度
  9. @end
  10.  
  11. #endif
  1. #import <Foundation/Foundation.h>
  2. #import "Activity.h"
  3.  
  4. @implementation Activity
  5. - (void) encodeWithCoder : (NSCoder *)encode {
  6. [encode encodeObject:self.m_name forKey:@"name"];
  7. [encode encodeObject:self.m_type forKey:@"type"];
  8. [encode encodeObject:self.m_doneTime forKey:@"doneTime"];
  9. [encode encodeObject:self.m_time forKey:@"time"];
  10. [encode encodeObject:self.m_doneActiveness forKey:@"doneActiveness"];
  11. [encode encodeObject:self.m_activeness forKey:@"activeness"];
  12. }
  13.  
  14. - (id)initWithCoder:(NSCoder *)aDecoder {
  15. if(self = [super init])
  16. {
  17. self.m_name = [aDecoder decodeObjectForKey:@"name"];
  18. self.m_type = [aDecoder decodeObjectForKey:@"type"];
  19. self.m_doneTime = [aDecoder decodeObjectForKey:@"doneTime"];
  20. self.m_time = [aDecoder decodeObjectForKey:@"time"];
  21. self.m_doneActiveness = [aDecoder decodeObjectForKey:@"doneActiveness"];
  22. self.m_activeness = [aDecoder decodeObjectForKey:@"activeness"];
  23. }
  24. return self;
  25. }
  26. @end

Apple-Watch开发1的更多相关文章

  1. Apple Watch开发快速入门教程

     Apple Watch开发快速入门教程  试读下载地址:http://pan.baidu.com/s/1eQ8JdR0 介绍:苹果为Watch提供全新的开发框架WatchKit.本教程是国内第一本A ...

  2. 快速玩转Apple Pay开发

    快速玩转Apple Pay开发 更新时间:2016年02月20日09时25分 来源:传智播客 Apple Pay 2016年2月18日上午,苹果公司宣布,与中国银联达成合作,正式在中国大陆上线Appl ...

  3. [转载]Apple Watch 开发详解

    Apple Watch 开发详解 Apple Watch现在对于第三方开发者来说更多的还是一块额外的屏幕.暂时WatchKit没有能给出足够的接口.现在Watch App的主要运算逻辑需要依赖iPho ...

  4. Apple Watch 开发详解

    Apple Watch 开发详解 Apple Watch现在对于第三方开发者来说更多的还是一块额外的屏幕.暂时WatchKit没有能给出足够的接口.现在Watch App的主要运算逻辑需要依赖iPho ...

  5. 为Apple Push开发的PHP PEAR 包:Services_Apple_PushNotification

    Apple Push Notification Service:通过苹果服务器向app用户推送消息,无需启动app. 苹果官方文档:http://developer.apple.com/library ...

  6. Apple Watch开发了一些细节和总结

    本文旨在总结最近Watch在发展中遇到的问题和细节 1.左右Watch真机调试问题 一般的情况下,你为IOS主应用创建了一个extention,比方说Today Extension .Xcode都会自 ...

  7. 苹果(APPLE)开发人员账号说明及注冊流程(99美元公司版/个人版及299美元企业版)

    APPLE的政策是,要公布到APP STORE必须用99美元的个人版或公司版Apple Developer Programs,要在非商店外下载仅仅能使用299美元的企业版iOS Developer E ...

  8. Apple Pay--iOS开发

    一.什么是Apple Pay? 1. 概念 Apple Pay,简单来说, 就是一种移动支付方式.通过Touch ID/ Passcode,用户可使用存储在iPhone 6, 6p等设备上的信用卡和借 ...

  9. Apple Watch开发之界面之间的正向传值

    主要分两种,一种是故事板中通过segue进行的传值,第二种是使用代码. 贴代码 24行代码是代码进行传值 35是故事板中的

  10. iOS Apple Watch 开发

    1. Watch OS 1 与 Watch OS 2 的区别 : OS 1 中界面运行在手表上,而代码(Extension)运行在手机端:OS 2 是纯正的手表原生(Native)应用 由于架构的改变 ...

随机推荐

  1. PDF转图片 C# with Adobe API

    PDF转图片大概有十几种方式,褒贬不一,我就详细给大家说一下我认为效率最高的方式,使用Adobe官方的SDK 安装acrobat reader 9.0以上即可,勾选如下组件.

  2. 一个c++给程序打log的单例模式类

    开发过程中需要给程序打log. 所以照着网上写了个单例模式的log类 #ifndef MISCLOGWRITER_H_ #define MISCLOGWRITER_H_ #include <io ...

  3. Login过滤器

    继承自ActionFilterAttibute public override void OnActionExecuting(ActionExecutingContext filterContext) ...

  4. activity学习(1) 生命周期理解

    可以忽略onWindowFocusChanged.onSaveInstanceState.onRestoreInstanceState几个事件,这几个事件官网中的生命周期里面没有提到.忽略掉这几个方法 ...

  5. Debug和Release之本质区别

    转自Debug和Release之本质区别 Debug 和 Release 编译方式的本质区别 Debug 通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序.Release 称为发 ...

  6. Apache HBase RPC身份验证中间人安全措施绕过漏洞(CVE-2013-2193)

    漏洞版本: Apache Group HBase 0.94.x Apache Group HBase 0.92.x 漏洞描述: BUGTRAQ ID: 61981 CVE(CAN) ID: CVE-2 ...

  7. android获取设备屏幕大小的方法

    // 通过WindowManager获取 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay( ...

  8. 可压Navier-Stokes方程组的爆破现象

    在 Z.P. Xin, Blowup of smooth solutions to the compressible Navier-Stokes  equations with compact den ...

  9. codeforce --- 237C

    C. Primes on Interval time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  10. 新手入门 acm 输入输出练习

    A + B Problem(1000) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...