在WatchKit中没有调用func session(..)

弗朗兹斯卡·里歇尔特(Franziska Reichelt)

我正在尝试3天才能完成这项工作,但事实并非如此:/

我想向手表发送一些消息。但是函数会话不会被调用。

在我的父母中,我使用以下代码打开会话:

- (void)viewDidLoad {

     [super viewDidLoad];

     if ([WCSession isSupported]) {
         WCSession *session = [WCSession defaultSession];
         session.delegate = self;
         [session activateSession];
     }

}

然后,如果要按下一个按钮,我想将字典发送到我的应用程序:

 -(void)clickBackButton{

     NSArray *obj = @[@"Mercedes-Benz SLK250", @"Mercedes-Benz E350"];
     NSArray *key = @[[NSNumber numberWithInt:13], [NSNumber numberWithInt:22]];
     NSDictionary *applicationDict = [NSDictionary dictionaryWithObject:obj forKey:key];
     [[WCSession defaultSession] transferUserInfo:applicationDict];

 }

在我的手表中,我将以下代码用于会话:

 override func willActivate() {
    super.willActivate()

    if (WCSession.isSupported()) {
        session = WCSession.defaultSession()
        session.delegate = self
        session.activateSession()
    }
}

而且这种方法永远不会被调用:

func session(session: WCSession, didFinishUserInfoTransfer userInfoTransfer: WCSessionUserInfoTransfer, error: NSError?) {
    print("session called")
}
ccjensen

您正在寻找的委托方法是session:didReceiveUserInfo:如果您阅读了委托方法上面的评论,您将看到在接收方(您的手表)实现的是在发送方调用的,以确认传输已完成!

    /** Called on the sending side after the user info transfer has successfully completed or failed with an error. Will be called on next launch if the sender was not running when the user info finished. */
- (void)session:(WCSession * __nonnull)session didFinishUserInfoTransfer:(WCSessionUserInfoTransfer *)userInfoTransfer error:(nullable NSError *)error;

/** Called on the delegate of the receiver. Will be called on startup if the user info finished transferring when the receiver was not running. */
- (void)session:(WCSession *)session didReceiveUserInfo:(NSDictionary<NSString *, id> *)userInfo;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

$_SESSION var 没有通过

php session 没有被破坏

WatchKit didReceiveApplicationContext没有被调用

AttributeError:“ scoped_session”对象没有属性“ session”

Django:“ SessionStore”对象没有属性“ session”

session_destroy()没有注销我

AttributeError:“ SecureCookieSession”对象没有属性“ Session”

AttributeError:模块“ tensorflow”没有属性“ Session”

Libtorrent Session_Status没有更新

'scoped_session'对象没有属性'create_all''scoped_session'对象没有属性'session'

有时request.session.session_key为None

$ _SESSION变量-session_start()有什么影响吗?

有没有办法检查某个值是否在 request.session.name 中?

在tf.Session()中循环

PHP:在$ _SESSION中存储“对象”

PHP中删除$_SESSION的问题

MVC 中的 OnInit 和 Session

$_SESSION['mydata'] 在 MW 中消失

在 codeigniter 中从 Session 登录 Userid

日期时间NO_()中的$ _session

CONSTANT 中的 PHP $_SESSION 变量

Flask错误:db:scoped_session'scoped_session'的实例没有'commit'memberpylint(no-member)

无法向 SQLAlchemy 提交数据:AttributeError: 'scoped_session' 对象没有属性 'session'

为什么在Hibernate中的session.delete()之后需要调用session.flush()?

PHP中的unset($ _ SESSION []),session_unset()和session_destroy()之间的区别

我在django的request.session中设置了一个键,但是没有效果

如果没有req.session.save(),会话将不会保存在Node.js中。

"errorMessage": "'Session' 对象在 AWS 中没有属性 'region_id'"

PHP session_start 没有在响应中设置 Set-Cookie 标头