zoukankan      html  css  js  c++  java
  • Apple-Watch开发1

    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 录音功能实现

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

    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);

        }

    //活动
    @interface Activity : NSObject
    @property(nonatomic, retain) NSString *m_name;               //名称
    @property(nonatomic, retain) NSString *m_type;               //日常活动、限时活动、节日活动
    @property(nonatomic, retain) NSNumber *m_doneTime;           //已经完成次数
    @property(nonatomic, retain) NSNumber *m_time;               //每日次数
    @property(nonatomic, retain) NSNumber *m_doneActiveness;     //已经完成活跃度
    @property(nonatomic, retain) NSNumber *m_activeness;         //每日活跃度
    @end
    
    #endif
    #import <Foundation/Foundation.h>
    #import "Activity.h"
    
    
    @implementation Activity
    - (void) encodeWithCoder : (NSCoder *)encode {
        [encode encodeObject:self.m_name forKey:@"name"];
        [encode encodeObject:self.m_type forKey:@"type"];
        [encode encodeObject:self.m_doneTime forKey:@"doneTime"];
        [encode encodeObject:self.m_time forKey:@"time"];
        [encode encodeObject:self.m_doneActiveness forKey:@"doneActiveness"];
        [encode encodeObject:self.m_activeness forKey:@"activeness"];
    }
    
    
    - (id)initWithCoder:(NSCoder *)aDecoder {
        if(self = [super init])
        {
            self.m_name =           [aDecoder decodeObjectForKey:@"name"];
            self.m_type =           [aDecoder decodeObjectForKey:@"type"];
            self.m_doneTime =       [aDecoder decodeObjectForKey:@"doneTime"];
            self.m_time =           [aDecoder decodeObjectForKey:@"time"];
            self.m_doneActiveness = [aDecoder decodeObjectForKey:@"doneActiveness"];
            self.m_activeness =     [aDecoder decodeObjectForKey:@"activeness"];
        }
        return self;
    }
    @end
  • 相关阅读:
    【工具类】图片压缩工具类,可压缩jpg, png等图片
    【Nginx用法】nginx location正则表达式写法,详解Nginx location 匹配规则(很详细哦)
    【Nginx异常】[error] 4236#29900: OpenEvent(“Global gx_reload_27128“) failed (5: Access is denied)
    【Nginx异常】Nginx启动一闪而过没反应,Nginx双击打开后,没有启动成功,也没有进程,且127.0.0.1:8080访问不到
    开启vue-element-ui打包生成报告
    Cas 5.2.x 使用 实现SSO单点登录的问题
    springmvc在使用@ModelAttribute注解获取Request和Response会产生线程并发不安全问题
    企业微信会话存档开发与问题
    高手怎么查找CPU过高的Java代码。具体到行
    ubuntu中清除开始菜单中的应用图标
  • 原文地址:https://www.cnblogs.com/wiessharling/p/4729889.html
Copyright © 2011-2022 走看看