【问题标题】:Redefinition of variable name with a different type [duplicate]用不同类型重新定义变量名[重复]
【发布时间】:2014-09-25 04:49:27
【问题描述】:

我正在尝试向我的应用程序发送推送通知。在这里,通过下面的代码,我试图获取设备令牌,但出现编译器错误:

使用不同类型重新定义“deviceToken”:“NSString__strong”与“NSData”__strong'

这是我的代码。

    NSString *deviceToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""] 
stringByReplacingOccurrencesOfString: @" " withString: @""];

【问题讨论】:

  • 在同一个作用域中不能有两个同名的变量。重命名其中一个。
  • 用 devToken 替换了 deviceToken.. 还是一样的错误..
  • 显示更多代码。显示您的NSData 版本的deviceToken
  • 您想获取设备令牌还是发送推送通知?
  • 您必须在某处声明另一个deviceToken,因为您在其上调用description 方法。

标签: objective-c variables compiler-errors scope


【解决方案1】:

使用此代码可以获得 deviceToken

NSString *deviceTokenId = [[[deviceToken description]
                  stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
                 stringByReplacingOccurrencesOfString:@" "
                 withString:@""];

【讨论】:

  • 是的,我上面使用的代码是旧方法,xcode5 不再支持...谢谢 sanjeet 的回答。
猜你喜欢
  • 1970-01-01
  • 2020-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多