2014-09-04 67 views
0

我已经很努力了使用的Vuforia SDK一场比赛,我想结合最好使用UrbanAirship推送通知(这是我的客户端请求)Unity3D推送通知的iOS和Android Vuforia&UrbanAirship

我一直在努力让推送通知在iOS和Android上都能正常工作,但没有运气,没有使用UrbanAirship,也没有任何其他方式,我也尝试了Pushwoosh Unity插件。

问题1:是否可以将UrbanAirship与Unity3d整合?任何链接/建议/样本会很好,我已经搜索,但无法找到任何相关的东西。

问题2 :(如果我理解正确的话)Vurforia SDK需要Android Manifest文件中的MAIN活动,这样可以阻止我实现Pushwoosh或其他类似插件的插件,以至于使用GCM(Google Cloud消息),他们也需要MAIN活动。

问题3:如果我已经从所有已阅读的网站/论坛/帖子中正确理解,GCM是向Android推送通知的方式。阅读关于GCM的一些信息,它是一个通用的双消息传递API,当应用程序没有运行时它可以用于推送通知吗?还是我完全在错误的轨道上?

对于长期问题,我知道并且表示歉意,但这是第一次处理推送通知,更不用说在iOS和Android上都可以使用的东西了。我真的很感激任何建议,如何得到这个工作。 TIA!

+0

wrt 1:我们也使用urbanairship,并且可以在旁边使用它,诀窍在于附加到应用程序级别,而不是主要活动。 – Rudolfwm 2014-09-05 14:20:27

+0

@Rudolfwm谢谢,多数民众赞成。您是否有机会发布如何按照您的建议将其附加到应用程序级别的示例? TIA! – 2014-09-05 21:53:55

回答

0

这是从Android插件我为城市飞艇

请注意,我扩展了应用程序的代码。你还需要一个意图接收者类。

package com.yourapp.urbanairship; 

import android.app.Application; 
import android.util.Log; 

import com.urbanairship.AirshipConfigOptions; 
import com.urbanairship.Logger; 
import com.urbanairship.UAirship; 
import com.urbanairship.push.CustomPushNotificationBuilder; 
import com.urbanairship.push.PushManager; 

public class UrbanAirShipPlugin extends Application { 


    @Override 
    public void onCreate() { 

     super.onCreate(); 

     AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this); 

    options.productionAppKey ="XXXXXXXXXXXXXXXXXXXXXXXXXX"; // from urban airship 
    options.productionAppSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXX"; // from urban airship 
    options.developmentAppKey ="XXXXXXXXXXXXXXXXXXXXXXXXXX"; // from urban airship 
    options.developmentAppSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXX";// from urban airship 
    options.gcmSender = "XXXXXXXXXXXXXX"; // from GOOGLE -> basically your project id 

    options.inProduction = true; 
    options.analyticsEnabled =false; 
    options.minSdkVersion=18; 

    //determines which app key to use 
    // Take off initializes the services 
    UAirship.takeOff(this, options); 
    PushManager.shared().setIntentReceiver(IntentReceiver.class); 

    } 
} 

这里是意图接收器类:

package your.package.name; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 

import com.urbanairship.UAirship; 
import com.urbanairship.push.GCMMessageHandler; 
import com.urbanairship.push.PushManager; 

import java.util.Arrays; 
import java.util.List; 
import java.util.Set; 

public class IntentReceiver extends BroadcastReceiver { 

    private static final String logTag = "PushSample"; 

    public static String APID_UPDATED_ACTION_SUFFIX = ".apid.updated"; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.i(logTag, "Received intent: " + intent.toString()); 
     String action = intent.getAction(); 

     if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) { 

      int id = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0); 

      Log.i(logTag, "Received push notification. Alert: " 
       + intent.getStringExtra(PushManager.EXTRA_ALERT) 
       + " [NotificationID="+id+"]"); 

      logPushExtras(intent); 

     } else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) { 

      Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT)); 

      logPushExtras(intent); 

      Intent launch = new Intent(Intent.ACTION_MAIN); 
      launch.setClassName(UAirship.shared().getApplicationContext(), "your.main.activity"); 
      launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

      UAirship.shared().getApplicationContext().startActivity(launch); 

     } else if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) { 
      Log.i(logTag, "Registration complete. APID:" + intent.getStringExtra(PushManager.EXTRA_APID) 
       + ". Valid: " +  intent.getBooleanExtra(PushManager.EXTRA_REGISTRATION_VALID, false)); 

      // Notify any app-specific listeners 
      Intent launch = new Intent(UAirship.getPackageName() + APID_UPDATED_ACTION_SUFFIX); 
      UAirship.shared().getApplicationContext().sendBroadcast(launch); 

     } else if (action.equals(GCMMessageHandler.ACTION_GCM_DELETED_MESSAGES)) { 
      Log.i(logTag, "The GCM service deleted "+intent.getStringExtra(GCMMessageHandler.EXTRA_GCM_TOTAL_DELETED)+" messages."); 
    } 

} 

/** 
* Log the values sent in the payload's "extra" dictionary. 
* 
* @param intent A PushManager.ACTION_NOTIFICATION_OPENED or ACTION_PUSH_RECEIVED intent. 
*/ 
    private void logPushExtras(Intent intent) { 
     Set<String> keys = intent.getExtras().keySet(); 
     for (String key : keys) { 

      //ignore standard C2DM extra keys 
      List<String> ignoredKeys = (List<String>)Arrays.asList(
       "collapse_key",//c2dm collapse key 
       "from",//c2dm sender 
       PushManager.EXTRA_NOTIFICATION_ID,//int id of generated notification (ACTION_PUSH_RECEIVED only) 
       PushManager.EXTRA_PUSH_ID,//internal UA push id 
       PushManager.EXTRA_ALERT);//ignore alert 
      if (ignoredKeys.contains(key)) { 
       continue; 
      } 
      Log.i(logTag, "Push Notification Extra: ["+key+" : " + intent.getStringExtra(key) + "]"); 
     } 
    } 
} 

另外请注意,您需要为应用程序扩展下一个添加插件com.yourapp.urbanairship名清单(所有你在那里需要其他的东西):

<application android:allowClearUserData="true" android:icon="@drawable/app_icon" android:label="@string/app_name" android:name="com.yourapp.urbanairship" android:debuggable="true"> 

不要忘记其他任何在你的清单urbanairship需要(见here

+0

感谢您的回答,我会尽我所能,在回邮后实施它。再次感谢! – 2014-09-09 12:07:38