How can I do in xCode the java code mentioned in the question?

1

This class on Android when enabled, I can close the app it keeps working and keep the cell screen lit like this

Keep screen lit:

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "watever");
    wl.acquire();

// Complete code:

public class StreamService extends Service {
private static final String TAG = "StreamService";


SharedPreferences prefs;
SharedPreferences.Editor editor;
Notification n;
NotificationManager notificationManager;
int notifId = 5315;
PowerManager.WakeLock wl;
IBinder b;

@Override
public IBinder onBind(Intent arg0) {
    int x = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
    arg0.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    return b;

}

@SuppressWarnings("deprecation")
@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "onCreate");
    //FAZ A TELA FICAR LIGADA. . ._
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "watever");
    wl.acquire();
    //__
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    editor = prefs.edit();
    notificationManager = (NotificationManager) getApplicationContext()
            .getSystemService(NOTIFICATION_SERVICE);
    Context context = getApplicationContext();
    String notifTitle = context.getResources().getString(R.string.app_name);
    String notifMessage = context.getResources().getString(R.string.buffering);
    n = new Notification();
    n.icon = R.drawable.icon;
    n.tickerText = "screen ON";
    n.when = System.currentTimeMillis();
    Intent nIntent = new Intent(context, MainActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(context, 0, nIntent, 0);
    n.setLatestEventInfo(context, notifTitle, notifMessage, pIntent);
    notificationManager.notify(notifId, n);
}
@SuppressWarnings("deprecation")
@Override
public void onStart(Intent intent, int startId) {
    Log.d(TAG, "onStart");
    editor.putBoolean("isPlaying", true);
    editor.commit();
    Context context = getApplicationContext();
    String notifMessage = context.getResources().getString(R.string.now_playing);
    n.icon = R.drawable.icon;
    n.tickerText = notifMessage;
    n.flags = Notification.FLAG_NO_CLEAR;
    n.when = System.currentTimeMillis();
    Intent nIntent = new Intent(context, MainActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(context, 0, nIntent, 0);
}

@Override
public void onDestroy() {
    Log.d(TAG, "onDestroy");
    notificationManager.cancel(notifId);
}
}

The goal is to close the app and keep the screen switched on, leaving in the notifications an option to re-open the app and deny this process when desired.

If someone can help me how I can do something similar to a extends class servise in xCode and a method similar to keeping the screen lit, every tip is valid.

    
asked by anonymous 29.01.2016 / 17:22

1 answer

1

Thanks for the attention, I was able to solve this problem through these 2 links.

This shows you how to work with notifications: How to implement an Apple push notification service APNS?

This shows how it leaves the screen always on: IOS - how to make the screen of the app is always on?

Hugs!

    
01.02.2016 / 14:11