text: function pushRegisterError(e,t){t&&t({success:!1,error:e})}function pushRegisterSuccess(e,t,r){var n=t.deviceToken;Cloud.PushNotifications.unsubscribe({device_token:Ti.App.Properties.getString("android.deviceToken"),user_id:e,type:"android"},function(){exports.subscribe("friends",n,function(e){r(e.success?{success:!0,msg:"Subscribe to channel: friends",data:t}:{success:!1,error:_resp2.data,msg:"Error Subscribing to channel: friends"})})})}exports.initialize=function(e,t,r){if(USER_ID=e.get("id"),"Simulator"===Ti.Platform.model)return void alert("Push ONLY works on Devices!");var n=e.get("id");n?(AndroidPush.clearStatus(),AndroidPush.debug=!0,AndroidPush.showTrayNotificationsWhenFocused=!0,AndroidPush.retrieveDeviceToken({success:function(e){Ti.API.debug("recieved device token",e.deviceToken),AndroidPush.addEventListener("callback",t),AndroidPush.enabled=!0,AndroidPush.focusAppOnPush=!1,pushRegisterSuccess(n,e,function(t){Ti.App.Properties.setString("android.deviceToken",e.deviceToken),r(t)})},error:function(e){AndroidPush.enabled=!1,AndroidPush.focusAppOnPush=!1,AndroidPush.removeEventListener("callback",t),pushRegisterError(e,r)}})):r&&r({success:!1,msg:"Must have User for Push Notifications"})},exports.subscribe=function(e,t,r){Cloud.PushNotifications.subscribe({channel:e,device_token:t,type:"android"},function(t){var n="Subscribed to "+e+" Channel";Ti.API.debug(n+": "+t.success),r(t.success?{success:!0,error:null,msg:n}:{success:!1,error:t.data,msg:"Error Subscribing to All Channels"})})},exports.pushUnsubscribe=function(e,t){Cloud.PushNotifications.unsubscribe(e,function(r){r.success?(Ti.API.debug("Unsubscribed from: "+e.channel),t({success:!0,error:null})):(Ti.API.error("Error unsubscribing: "+e.channel),Ti.API.error(JSON.stringify(r,null,2)),t({success:!1,error:r}))})},exports.sendPush=function(e,t){if(null===Alloy.Globals.pushToken)return void t({success:!1,error:"Device Not Registered For Notifications!"});var r={channel:"friends",payload:e.payload};e.friends&&(r.friends=e.friends),e.to_ids&&(r.to_ids=e.to_ids),Cloud.PushNotifications.notify(r,function(e){if(e.success)t({success:!0});else{var r=e.error&&e.message||JSON.stringify(e);Ti.API.error(r),t({success:!1,error:r})}})},exports.getChannels=function(e,t){var r=Ti.Network.createHTTPClient(),n="production"===Titanium.App.deployType,i="acs-api-key-"+(n?"production":"development"),o="https://api.cloud.appcelerator.com/v1/push_notification/query.json?key=";o+=Ti.App.Properties.getString(i),o+="&user_id="+e.id,r.open("GET",o),r.setRequestHeader("Accept","application/json"),r.onerror=function(e){alert(e),Ti.API.info(" "+String(e))},r.onload=function(){try{Ti.API.debug(" "+r.responseText);var e=JSON.parse(r.responseText),n=e.response.subscriptions[0];Ti.API.info(JSON.stringify(n)),t&&t({success:!0,data:n})}catch(i){Ti.API.error(" "+String(i)),t&&t({success:!1,data:null,error:i})}},r.send()};