2017-03-31 43 views
-1

“shared()”方法由于某种原因未被识别,这阻止了我的应用程序的代码编译。我看到的错误是:Urban Airship“错误:找不到符号方法shared()”

error: cannot find symbol method shared() 

我在我使用这个“的build.gradle(模块:应用程序)”文件:

dependencies { 
    ...................... 
    // Urban Airship SDK 
    compile 'com.urbanairship.android:urbanairship-sdk:8.3.+' 
    ...................... 
} 

我想这个“共享()”方法将包括在我正在呼叫的Urban Airship SDK版本8.3。+中。当我看到城市飞艇示例应用程序所提供的“共享()”方法在https://github.com/urbanairship/android-library/blob/master/urbanairship-sdk/src/main/java/com/urbanairship/UAirship.java声明:

/** 
* Returns the shared UAirship singleton instance. This method will block 
* until airship is ready. 
* 
* @return The UAirship singleton. 
* @throws IllegalStateException if takeoff is not called prior to this method. 
*/ 
@NonNull 
public static UAirship shared() { 
    synchronized (airshipLock) { 
     if (!isTakingOff && !isFlying) { 
      throw new IllegalStateException("Take off must be called before shared()"); 
     } 

     return waitForTakeOff(0); 
    } 
} 

一下,为什么任何想法“共享()”方法不适用于我?这是我如何在我的代码使用它的一个例子,我把它几次从源代码的不同部分,但它始终是相同的,该方法不认可:

String appid=PushManager.shared().getAPID(); 

谢谢。

+0

顺便说一句,当我在依赖关系中为Urban Airship SDK使用“编译文件('libs/urbanairship-lib-3.3.0.jar')”时,它对我来说工作正常。现在我升级了,我在我的依赖中使用它:“compile'c​​om.urbanairship.android:urbanairship-sdk:8.3.+'”。现在“shared()”方法不适用于我。我知道他们在Urban Airship Sample应用中使用它,例如https://github.com/urbanairship/android-library/blob/master/urbanairship-sdk/src/main/java/com/urbanairship/UAirship.java :“UAirship飞艇= UAirship.shared();”。 –

+0

我在http://docs.urbanairship.com/api/ua/#post-api-custom-events上阅读以下信息:“Android 5.0 SDK之前:PushManager.shared()。setDeviceTagsEnabled(false); Android SDK 5.0或更高版本:UAirship.shared()。getPushManager().setDeviceTagsEnabled(false);“。我想问题是我的代码之前使用的是Urban Airship SDK 3.3.0,现在我升级到8.3。+,所以我需要尊重新的Urban Airship SDK的语法。 –

+0

我也在http://stackoverflow.com/questions/26717398/urbanairship-android-unable-to-getapid找到了这个信息:'APID不再用在5.x系列的Urban Airship中。而是使用新的“通道”标识符。它与APID基本相同。“所以不是“String appid = PushManager.shared()。getAPID();”我可能应该有“String appid = UAirship.shared()。getPushManager()。getChannelId();”,它不会为我抛出任何错误,它也使用我在问题中提到的“shared()”方法。 –

回答

1

3.3至8.3是相当大的更新。我们现在使用“频道”而不是“apids”,本质上是相同的,但已经更新了一些。我们还删除了单个模块的大部分单例访问器,并将它们移至UAirship实例。新代码应该是

UAirship.shared().getPushManager().getChannelId();

我建议采取看看Urban Airship Android Guide还有migration guide。除API更改外,我们对如何对listeningcustomizing push notifications进行了大量更改。尽管现在我们通过推送API和飞艇配置来提供大多数选项,但是定制通知并不是必要的。