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
  • 相关阅读:
    “您的外卖订单正在由机器人配送中”:探访送货机器人进楼宇
    外媒:比特币大陆将于9月IPO 规模或高达180亿美元
    网站被挂马的处理办法以及预防措施
    【学习】linux环境下nginx文件彻底删除
    【学习】SpringBoot之全局异常处理器
    【学习】SpringBoot之自定义拦截器
    _parameter:解决There is no getter for property named in class java.lang.String
    Window安装Redis并设置为开机启动
    SpringBoot 使用定时任务动态执行任务
    网易云信(创建账号,添加好友,获取好友关系,发送系统消息《推送》,删除好友,修改用户信息)
  • 原文地址:https://www.cnblogs.com/wiessharling/p/4729889.html
Copyright © 2011-2022 走看看