我正在尝试为我的iOS应用程序安装Google Cloud Messaging(使用swift).我已将它添加到我的Podfile中,如下所示:
# Uncomment this line to define a global platform for your project
# platform :ios, '8.2'
use_frameworks!
target 'Project' do
pod 'Alamofire', '~> 1.2'
pod 'Google/CloudMessaging'
end
target 'ProjectTests' do
end
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试安装依赖项时,出现错误(见下文).在我添加GoogleCloudMessaging之前,它运行良好.我尝试创建一个新项目并将其添加到那里,看它是否有效,我得到了同样的错误.
Analyzing dependencies
Downloading dependencies
Installing Alamofire (1.2.3)
Installing GGLInstanceID (1.0.0)
Installing Google (1.0.7)
Installing GoogleCloudMessaging (1.0.3)
Installing GoogleInterchangeUtilities (1.0.0)
Installing GoogleNetworkingUtilities (1.0.0)
Installing GoogleSymbolUtilities (1.0.0)
Installing GoogleUtilities (1.0.1)
[!] The '<Project name>' target has transitive dependencies that include static binaries: (/Users/User/Documents/Test/Pods/GGLInstanceID/Libraries/libGGLInstanceIDLib.a, /Users/User/Documents/Test/Pods/Google/Libraries/libGGLCloudMessaging.a, /Users/User/Documents/Test/Pods/Google/Libraries/libGGLCore.a, /Users/User/Documents/Test/Pods/GoogleCloudMessaging/Libraries/libGcmLib.a, /Users/User/Documents/Test/Pods/GoogleInterchangeUtilities/Libraries/libProtocolBuffers.a, …Run Code Online (Sandbox Code Playgroud) 我目前正致力于将GCM通知实施到我的应用中.
我遇到的问题是onMessageReceived()我的GcmListenerService实现方法没有被调用.我很好地从GCM服务器接收数据,因为它会自动生成通知(我希望使用该onMessageReceived()方法将其替换为我自己的通知),但之后我的日志调用都没有打印在日志中.
从服务器发送到GCM服务器的JSON
{
"notification" : {
"title" : "Title",
"text" : "Message",
"icon" : "@drawable\/ic_notification",
"click_action" : "OPEN_MAIN_ACTIVITY"
},
"registration_ids":[
"xxxx", "xxxx", "xxxx", "etc"
]
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml(仅限GCM部分)
<!-- GCM START -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.my.package" />
</intent-filter>
</receiver>
<service
android:name=".Services.ListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".Services.IDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<!-- GCM END -->
Run Code Online (Sandbox Code Playgroud)
GcmListenerService(只是一个快速打印,看看它是否被调用)
public class ListenerService extends GcmListenerService …Run Code Online (Sandbox Code Playgroud)